Skip to content

Commit

Permalink
Improve interactive view error/warning capture
Browse files Browse the repository at this point in the history
  • Loading branch information
ajyoon committed Oct 6, 2023
1 parent 7402910 commit 77fae51
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### 0.1.10 (unreleased)
* Improve interactive view error/warning capture

### 0.1.9
* Update experimental in-eval ref lookup. Now exposed by two
functions, `bml.ref(id)` (returns rendered output of ref) and
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"releaseTest": "node test/releaseTest.js",
"checkTypes": "./node_modules/.bin/tsc --noEmit",
"buildOnly": "./node_modules/.bin/parcel build",
"buildDebug": "./node_modules/.bin/parcel build --no-optimize",
"build": "npm run checkTypes && npm run buildOnly && npm run releaseTest",
"preversion": "npm test",
"version": "npm run build"
Expand Down
16 changes: 8 additions & 8 deletions src/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ export function launchInteractive(scriptPath: string, settings: RenderSettings)
capturedErr: '',
};

let initialStderrWrite = process.stderr.write;
process.stderr.write = (data: any) => {
const realConsoleError = console.error;
const realConsoleWarn = console.warn;
console.error = (data: any) => {
state.capturedErr += data;
};

try {
runInternal(scriptPath, settings, state)
} finally {
process.stderr.write = initialStderrWrite;
}
console.warn = console.error;
// Ideally, these console overrides should be cleaned up afterward,
// but the interactive view runs async so it'd have to be attached
// to a shutdown callback of some kind.
runInternal(scriptPath, settings, state)
}

export function runInternal(scriptPath: string, settings: RenderSettings, state: InteractiveState) {
Expand Down

0 comments on commit 77fae51

Please sign in to comment.