Skip to content

Commit

Permalink
fix: show error always after logUpdate.clear
Browse files Browse the repository at this point in the history
  • Loading branch information
snowyu committed Jun 27, 2024
1 parent 008a7a5 commit 26494c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ $ npm install -g @offline-ai/cli
$ ai COMMAND
running command...
$ ai (--version)
@offline-ai/cli/0.0.12 linux-x64 node-v20.14.0
@offline-ai/cli/0.0.13 linux-x64 node-v20.14.0
$ ai --help [COMMAND]
USAGE
$ ai COMMAND
Expand Down Expand Up @@ -303,7 +303,7 @@ EXAMPLES
$ ai agent publish <agent-name>
```

_See code: [src/commands/agent/index.ts](https://github.com/offline-ai/cli/blob/v0.0.12/src/commands/agent/index.ts)_
_See code: [src/commands/agent/index.ts](https://github.com/offline-ai/cli/blob/v0.0.13/src/commands/agent/index.ts)_

## `ai autocomplete [SHELL]`

Expand Down Expand Up @@ -376,7 +376,7 @@ EXAMPLES
$ ai brain download <brain-name>
```

_See code: [src/commands/brain/index.ts](https://github.com/offline-ai/cli/blob/v0.0.12/src/commands/brain/index.ts)_
_See code: [src/commands/brain/index.ts](https://github.com/offline-ai/cli/blob/v0.0.13/src/commands/brain/index.ts)_

## `ai brain dn [NAME]`

Expand Down Expand Up @@ -504,7 +504,7 @@ EXAMPLES
$ ai brain download <brain-name> [-q <QUANT>]
```

_See code: [src/commands/brain/download.ts](https://github.com/offline-ai/cli/blob/v0.0.12/src/commands/brain/download.ts)_
_See code: [src/commands/brain/download.ts](https://github.com/offline-ai/cli/blob/v0.0.13/src/commands/brain/download.ts)_

## `ai brain list [NAME]`

Expand Down Expand Up @@ -536,7 +536,7 @@ ALIASES
$ ai brain search
```

_See code: [src/commands/brain/list.ts](https://github.com/offline-ai/cli/blob/v0.0.12/src/commands/brain/list.ts)_
_See code: [src/commands/brain/list.ts](https://github.com/offline-ai/cli/blob/v0.0.13/src/commands/brain/list.ts)_

## `ai brain search [NAME]`

Expand Down Expand Up @@ -603,7 +603,7 @@ EXAMPLES
}
```

_See code: [src/commands/config/index.ts](https://github.com/offline-ai/cli/blob/v0.0.12/src/commands/config/index.ts)_
_See code: [src/commands/config/index.ts](https://github.com/offline-ai/cli/blob/v0.0.13/src/commands/config/index.ts)_

## `ai config save [DATA]`

Expand Down Expand Up @@ -643,7 +643,7 @@ GLOBAL FLAGS
--json Format output as json.
```

_See code: [src/commands/config/save.ts](https://github.com/offline-ai/cli/blob/v0.0.12/src/commands/config/save.ts)_
_See code: [src/commands/config/save.ts](https://github.com/offline-ai/cli/blob/v0.0.13/src/commands/config/save.ts)_

## `ai help [COMMAND]`

Expand Down Expand Up @@ -1004,7 +1004,7 @@ EXAMPLES
│[info]:Start Script: ...
```

_See code: [src/commands/run/index.ts](https://github.com/offline-ai/cli/blob/v0.0.12/src/commands/run/index.ts)_
_See code: [src/commands/run/index.ts](https://github.com/offline-ai/cli/blob/v0.0.13/src/commands/run/index.ts)_

## `ai version`

Expand Down
15 changes: 12 additions & 3 deletions src/lib/run-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,18 @@ export async function runScript(filename: string, options: IRunScriptOptions) {
})
}

let lastError: any
try {
await runtime.run(options.data)
} catch(error: any) {
if (error.name !== 'AbortError') {throw error}
} finally {
lastError = error.name + (error.data?.what ? ':'+error.data.what : '')
} finally {
if (!isSilence) {logUpdate.clear(options.consoleClear)}
if (lastError) {
console.log(colors.magentaBright(`<${lastError}>`))
lastError = undefined
}
}

let result = runtime.result
Expand Down Expand Up @@ -244,10 +250,13 @@ export async function runScript(filename: string, options: IRunScriptOptions) {
result = await runtime.$interact(llmOptions)
} catch(error: any) {
if (error.name !== 'AbortError') {throw error}
const what = error.data?.what ? ':'+error.data.what : ''
input.write(colors.magentaBright(`<${error.name+what}>`))
lastError = error.name + (error.data?.what ? ':'+error.data.what : '')
} finally {
if (!isSilence) {logUpdate.clear(options.consoleClear)}
if (lastError) {
input.write(colors.magentaBright(`<${lastError}>\n`))
lastError = undefined
}
}
if (result) {
if (typeof result !== 'string') { result = ux.colorizeJson(result, {pretty: true, theme: options.theme?.json})}
Expand Down
2 changes: 1 addition & 1 deletion src/oclif/commands/run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class RunScript extends AICommand {
...AICommand.flags,
...AICommonFlags,
'consoleClear': Flags.boolean({
aliases: ['console-clear'],
aliases: ['console-clear', 'ConsoleClear', 'Console-clear', 'Console-Clear'],
description: 'Whether console clear after stream output, default to true in interactive, false to non-interactive',
allowNo: true,
}),
Expand Down

0 comments on commit 26494c9

Please sign in to comment.