From b6f44047609d68f03cb34cab9221b81eb0560c01 Mon Sep 17 00:00:00 2001 From: 0xZensh Date: Sun, 20 Oct 2024 21:22:51 +0800 Subject: [PATCH] fix: fix error catching in TS package --- Cargo.lock | 12 ++++++------ Cargo.toml | 2 +- src/ic_oss_bucket/src/store.rs | 15 ++++++++------- src/ic_oss_ts/package.json | 3 ++- src/ic_oss_ts/src/queue.ts | 2 +- src/ic_oss_ts/src/types.ts | 1 - src/ic_oss_ts/src/uploader.ts | 3 ++- 7 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ccfad34..4754d41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1324,7 +1324,7 @@ dependencies = [ [[package]] name = "ic-oss" -version = "0.9.5" +version = "0.9.6" dependencies = [ "bytes", "candid", @@ -1341,7 +1341,7 @@ dependencies = [ [[package]] name = "ic-oss-can" -version = "0.9.5" +version = "0.9.6" dependencies = [ "candid", "ciborium", @@ -1354,7 +1354,7 @@ dependencies = [ [[package]] name = "ic-oss-cli" -version = "0.9.5" +version = "0.9.6" dependencies = [ "anyhow", "candid", @@ -1375,7 +1375,7 @@ dependencies = [ [[package]] name = "ic-oss-types" -version = "0.9.5" +version = "0.9.6" dependencies = [ "base64 0.21.7", "candid", @@ -1466,7 +1466,7 @@ dependencies = [ [[package]] name = "ic_oss_bucket" -version = "0.9.5" +version = "0.9.6" dependencies = [ "base64 0.21.7", "candid", @@ -1486,7 +1486,7 @@ dependencies = [ [[package]] name = "ic_oss_cluster" -version = "0.9.5" +version = "0.9.6" dependencies = [ "candid", "ciborium", diff --git a/Cargo.toml b/Cargo.toml index 8b2f25a..66d2350 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ strip = true opt-level = 's' [workspace.package] -version = "0.9.5" +version = "0.9.6" edition = "2021" repository = "https://github.com/ldclabs/ic-oss" keywords = ["file", "storage", "oss", "s3", "icp"] diff --git a/src/ic_oss_bucket/src/store.rs b/src/ic_oss_bucket/src/store.rs index 1a52c71..32964b9 100644 --- a/src/ic_oss_bucket/src/store.rs +++ b/src/ic_oss_bucket/src/store.rs @@ -1302,7 +1302,6 @@ pub mod fs { } checker(&file)?; - file.updated_at = now_ms; file.filled += chunk.len() as u64; if file.filled > max { @@ -1313,16 +1312,18 @@ pub mod fs { r.borrow_mut() .insert(FileId(file_id, chunk_index), Chunk(chunk)) }) { - None => { - if file.chunks <= chunk_index { - file.chunks = chunk_index + 1; - } - } + None => {} Some(old) => { - file.filled -= old.0.len() as u64; + if chunk_index < file.chunks { + file.filled = file.filled.saturating_sub(old.0.len() as u64); + } } } + if file.chunks <= chunk_index { + file.chunks = chunk_index + 1; + } + let filled = file.filled; if file.size > 0 && filled > file.size { Err(format!( diff --git a/src/ic_oss_ts/package.json b/src/ic_oss_ts/package.json index 53ca906..efc2e31 100644 --- a/src/ic_oss_ts/package.json +++ b/src/ic_oss_ts/package.json @@ -1,6 +1,6 @@ { "name": "@ldclabs/ic_oss_ts", - "version": "0.9.5", + "version": "0.9.6", "type": "module", "description": "The Typescript version of the client SDK for the ic-oss cluster.", "license": "MIT", @@ -20,6 +20,7 @@ "files": [ "candid", "dist", + "src", "package.json", "LICENSE", "README.md" diff --git a/src/ic_oss_ts/src/queue.ts b/src/ic_oss_ts/src/queue.ts index bc7fc0a..623491e 100644 --- a/src/ic_oss_ts/src/queue.ts +++ b/src/ic_oss_ts/src/queue.ts @@ -25,7 +25,7 @@ export class ConcurrencyQueue { result .then(() => (this.#total += 1)) - .catch(this.#abort) + .catch((err) => this.#abort(err)) .finally(() => { this.#pending.delete(fn) this.#results.delete(result) diff --git a/src/ic_oss_ts/src/types.ts b/src/ic_oss_ts/src/types.ts index 563322d..a83f5fc 100644 --- a/src/ic_oss_ts/src/types.ts +++ b/src/ic_oss_ts/src/types.ts @@ -46,7 +46,6 @@ export interface UploadFileChunksResult { id: number filled: number uploadedChunks: number[] - error?: unknown // if any error occurs during upload } export interface Progress { diff --git a/src/ic_oss_ts/src/uploader.ts b/src/ic_oss_ts/src/uploader.ts index 5e7b841..3cf3f91 100644 --- a/src/ic_oss_ts/src/uploader.ts +++ b/src/ic_oss_ts/src/uploader.ts @@ -156,7 +156,8 @@ export class Uploader { content_type: [] }) } catch (err) { - rt.error = err + ;(err as any).data = rt + throw err } return rt