Validate template w autosubmit#31
Conversation
In the case that a default for a param is invalid by its own validation function, an Error will be thrown reporting the param's `name` and the `msg.
| }) | ||
|
|
||
| this._rl.input?.setMode(tty.constants.MODE_RAW) | ||
| if ('setMode' in this._rl.input) this._rl.input.setMode(tty.constants.MODE_RAW) |
There was a problem hiding this comment.
Adjusted this optional chaining to an explicit check for setMode() because the intent seems to set the mode if the stdin is a TTY. With it possibly being a Pipe instead, the optional chaining doesn't protect against calling setMode.
There was a problem hiding this comment.
Pull Request Overview
Adds default-value validation in the autosubmit flow and tests around failure and success cases
- Introduces two new tests (
autosubmit validation failsandautosubmit validation passes) intest/terminal.test.js - Updates
#autosubmitinterminal.jsto validate defaults, print to stderr, and throw on failure - Changes the raw‐mode guard for the readline input stream
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/terminal.test.js | Added tests to verify autosubmit rejects invalid defaults and accepts valid ones |
| terminal.js | Guarded setMode, made #autosubmit async with default validation and error reporting |
Comments suppressed due to low confidence (3)
terminal.js:150
- [nitpick] This private async method now encapsulates default validation logic; adding a brief JSDoc comment would clarify its purpose, parameters, and return value for future maintainers.
async #autosubmit () {
terminal.js:153
- [nitpick] Shifting elements directly from
this._paramsmutates the instance and prevents rerunning the prompt. Consider iterating over a shallow copy ([...this._params]) to preserve the original array.
while (this._params.length) {
terminal.js:162
- [nitpick] Including a trailing newline in the thrown error message may be unexpected for callers. It might be cleaner to omit
\nfrom theErrorconstructor and handle newlines only when writing to stderr.
throw Error(`Validating '${param.name}' parameter default failed: ${param.msg}\n`)
| }) | ||
|
|
||
| this._rl.input?.setMode(tty.constants.MODE_RAW) | ||
| if ('setMode' in this._rl.input) this._rl.input.setMode(tty.constants.MODE_RAW) |
There was a problem hiding this comment.
[nitpick] Guarding with in will throw if this._rl.input is null or undefined. Consider checking existence first, e.g. if (this._rl.input?.setMode) or if (this._rl.input && typeof this._rl.input.setMode === 'function') to avoid possible runtime errors.
| if ('setMode' in this._rl.input) this._rl.input.setMode(tty.constants.MODE_RAW) | |
| if (this._rl.input?.setMode) this._rl.input.setMode(tty.constants.MODE_RAW) |
In the case that a default for a param is invalid by its own validation function, an Error will be thrown reporting the param's
nameand themsg.Validation stops after the first validation that fails, prints to stderr and throws the same error. The error is thrown in addition to signal to the caller that something when wrong with running the interaction and the respond accordingly.