mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Fix promise error handling and improve rename docs
- Add catch {} for promise.reject/resolve in finalize() (API change)
- Expand Bun.rename() docs with function signature and conflict mode table
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -154,6 +154,8 @@ await Bun.write("index.html", response);
|
||||
|
||||
## Renaming files (`Bun.rename()`)
|
||||
|
||||
`Bun.rename(from, to, conflict?): Promise<void>`
|
||||
|
||||
Atomically rename or move files and directories. Similar to Node.js `fs.promises.rename()` but with an optional third parameter for conflict resolution.
|
||||
|
||||
```ts
|
||||
@@ -167,6 +169,14 @@ await Bun.rename("file1.txt", "file2.txt", "swap");
|
||||
await Bun.rename("source.txt", "dest.txt", "no-replace");
|
||||
```
|
||||
|
||||
The `conflict` parameter controls behavior when the destination already exists:
|
||||
|
||||
| Mode | Description |
|
||||
| ---- | ----------- |
|
||||
| `"replace"` | Replace destination if it exists (default) |
|
||||
| `"swap"` | Atomically swap the two files (Linux/macOS only, falls back to `"replace"` on Windows) |
|
||||
| `"no-replace"` | Fail with an error if destination exists |
|
||||
|
||||
---
|
||||
## Incremental writing with `FileSink`
|
||||
|
||||
|
||||
@@ -840,10 +840,10 @@ const RenameJob = struct {
|
||||
.err => |*err| {
|
||||
defer err.deinit();
|
||||
const error_instance = globalThis.createErrorInstance("rename failed: errno {d}", .{err.errno});
|
||||
promise.reject(globalThis, error_instance);
|
||||
promise.reject(globalThis, error_instance) catch {};
|
||||
},
|
||||
.result => {
|
||||
promise.resolve(globalThis, jsc.JSValue.js_undefined);
|
||||
promise.resolve(globalThis, jsc.JSValue.js_undefined) catch {};
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user