refactor(types): consolidate duplicated errno and JSON type helpers#2447
Conversation
Follow-up to PR #2422. Addresses review warnings and suggestions: 1. Extract shared isErrnoException/isPermissionError into src/lib/errno.ts - Unifies 6 duplicate definitions (config-io, credentials, http-probe, onboard, onboard-session, registry) into a single source of truth - Accepts `unknown` so callers never need instanceof Error pre-casts - Simplifies catch blocks across onboard-session.ts and registry.ts 2. Extract shared JSON recursive types into src/lib/json-types.ts - Unifies LooseScalar/LooseValue/LooseObject (onboard, agent-onboard), PolicyScalar/PolicyValue/PolicyObject (policies), and SessionJsonPrimitive/SessionJsonValue (onboard-session) - Plugin types (PluginScalar/PluginValue/PluginRecord) kept in-place since nemoclaw/src/ compiles separately from the CLI 3. Add Reflect.get/Reflect.set convention comment in usage-notice.ts explaining why the pattern is preferred over `as Record<…>` casts 4. Document the ws-proxy-fix.ts !host guard behavioral change explaining why it falls through to the original request instead of attempting a tunnel with an undefined host Signed-off-by: Jess Yaunches <jyaunches@nvidia.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughConsolidates errno and JSON type utilities into new shared modules ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
… top Address self-review nits: - Add clarifying comment on config-io.ts local JSON types explaining why they differ from json-types.ts (no undefined in strict JSON) - Move import statement in policies.ts above CJS require() block for consistent style with other modules Signed-off-by: Jess Yaunches <jyaunches@nvidia.com>
Add non-null assertions for Array.pop() returns and explicit parameter types for .some()/.find() callbacks that lost type inference after the errno/JSON type consolidation in #2447. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…VIDIA#2447) ## Summary Follow-up to PR NVIDIA#2422 (`refactor(types): tighten repo-wide type boundaries`). Addresses the review warnings and suggestions from triage. ## Changes ### 1. Shared `isErrnoException` / `isPermissionError` — `src/lib/errno.ts` PR NVIDIA#2422 removed all `@ts-nocheck` markers, which required each module to define its own `isErrnoException` + `ErrnoLike` type locally. This resulted in 6 slightly different copies across `config-io`, `credentials`, `http-probe`, `onboard`, `onboard-session`, and `registry`. This PR extracts a single canonical version into `src/lib/errno.ts` that: - Accepts `unknown` so callers never need an `instanceof Error` pre-cast - Checks for both `code` and `errno` properties (covering all Node.js error shapes) - Includes a convenience `isPermissionError` for the common EACCES/EPERM guard This also simplifies many catch blocks that previously did `error instanceof Error && isErrnoException(error)` — the redundant `instanceof Error` check is now handled inside the shared function. ### 2. Shared JSON recursive types — `src/lib/json-types.ts` PR NVIDIA#2422 introduced identical Scalar/Value/Object type triples in multiple modules: - `LooseScalar` / `LooseValue` / `LooseObject` in `onboard.ts` and `agent-onboard.ts` - `PolicyScalar` / `PolicyValue` / `PolicyObject` in `policies.ts` - `SessionJsonPrimitive` / `SessionJsonValue` / `UnknownRecord` in `onboard-session.ts` This PR extracts canonical `JsonScalar` / `JsonValue` / `JsonObject` types into `src/lib/json-types.ts`. Each module re-aliases them under its domain names for readability. > **Note:** The plugin types (`PluginScalar`/`PluginValue`/`PluginRecord` in `nemoclaw/src/index.ts`) are intentionally kept in-place because the plugin compiles separately from the CLI and cannot share imports. ### 3. `Reflect.get` / `Reflect.set` convention comment Adds a clarifying comment at the first usage site (`usage-notice.ts`) explaining why `Reflect.get` is preferred over `as Record<…>` casts throughout the codebase — it avoids widening the target type and satisfies `no-unsafe-member-access` lint rules. ### 4. `ws-proxy-fix.ts` behavioral guard documentation Documents the `!host` null guard in the Discord WebSocket tunnel path, explaining that the previous code would have attempted a tunnel with an undefined host (which would fail downstream anyway). The guard now explicitly falls through to the original `https.request` unchanged. ## Type of Change - [x] Code change (feature, bug fix, or refactor) - [ ] Code change with doc updates - [ ] Doc only (prose changes, no code sample modifications) - [ ] Doc only (includes code sample changes) ## Verification - [x] `tsc -p tsconfig.cli.json --noEmit` passes - [x] `npm test` passes (only pre-existing failures in install-preflight and ssrf-parity) - [x] Tests added for new `errno.ts` module (15 test cases) - [x] No secrets, API keys, or credentials committed - [ ] Docs updated for user-facing behavior changes - [ ] `make docs` builds without warnings (doc changes only) ## AI Disclosure - [x] AI-assisted — tool: pi coding agent --- Signed-off-by: Jess Yaunches <jyaunches@nvidia.com> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved WebSocket proxy handling to avoid creating tunnels when the request target host is undefined. * **Tests** * Added tests validating errno/permission detection utilities. * **Documentation** * Added explanatory comment clarifying property-access rationale. * **Chores** * Centralized JSON-type aliases and errno helpers for consistent error handling across modules. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jess Yaunches <jyaunches@nvidia.com>
…VIDIA#2447) ## Summary Follow-up to PR NVIDIA#2422 (`refactor(types): tighten repo-wide type boundaries`). Addresses the review warnings and suggestions from triage. ## Changes ### 1. Shared `isErrnoException` / `isPermissionError` — `src/lib/errno.ts` PR NVIDIA#2422 removed all `@ts-nocheck` markers, which required each module to define its own `isErrnoException` + `ErrnoLike` type locally. This resulted in 6 slightly different copies across `config-io`, `credentials`, `http-probe`, `onboard`, `onboard-session`, and `registry`. This PR extracts a single canonical version into `src/lib/errno.ts` that: - Accepts `unknown` so callers never need an `instanceof Error` pre-cast - Checks for both `code` and `errno` properties (covering all Node.js error shapes) - Includes a convenience `isPermissionError` for the common EACCES/EPERM guard This also simplifies many catch blocks that previously did `error instanceof Error && isErrnoException(error)` — the redundant `instanceof Error` check is now handled inside the shared function. ### 2. Shared JSON recursive types — `src/lib/json-types.ts` PR NVIDIA#2422 introduced identical Scalar/Value/Object type triples in multiple modules: - `LooseScalar` / `LooseValue` / `LooseObject` in `onboard.ts` and `agent-onboard.ts` - `PolicyScalar` / `PolicyValue` / `PolicyObject` in `policies.ts` - `SessionJsonPrimitive` / `SessionJsonValue` / `UnknownRecord` in `onboard-session.ts` This PR extracts canonical `JsonScalar` / `JsonValue` / `JsonObject` types into `src/lib/json-types.ts`. Each module re-aliases them under its domain names for readability. > **Note:** The plugin types (`PluginScalar`/`PluginValue`/`PluginRecord` in `nemoclaw/src/index.ts`) are intentionally kept in-place because the plugin compiles separately from the CLI and cannot share imports. ### 3. `Reflect.get` / `Reflect.set` convention comment Adds a clarifying comment at the first usage site (`usage-notice.ts`) explaining why `Reflect.get` is preferred over `as Record<…>` casts throughout the codebase — it avoids widening the target type and satisfies `no-unsafe-member-access` lint rules. ### 4. `ws-proxy-fix.ts` behavioral guard documentation Documents the `!host` null guard in the Discord WebSocket tunnel path, explaining that the previous code would have attempted a tunnel with an undefined host (which would fail downstream anyway). The guard now explicitly falls through to the original `https.request` unchanged. ## Type of Change - [x] Code change (feature, bug fix, or refactor) - [ ] Code change with doc updates - [ ] Doc only (prose changes, no code sample modifications) - [ ] Doc only (includes code sample changes) ## Verification - [x] `tsc -p tsconfig.cli.json --noEmit` passes - [x] `npm test` passes (only pre-existing failures in install-preflight and ssrf-parity) - [x] Tests added for new `errno.ts` module (15 test cases) - [x] No secrets, API keys, or credentials committed - [ ] Docs updated for user-facing behavior changes - [ ] `make docs` builds without warnings (doc changes only) ## AI Disclosure - [x] AI-assisted — tool: pi coding agent --- Signed-off-by: Jess Yaunches <jyaunches@nvidia.com> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved WebSocket proxy handling to avoid creating tunnels when the request target host is undefined. * **Tests** * Added tests validating errno/permission detection utilities. * **Documentation** * Added explanatory comment clarifying property-access rationale. * **Chores** * Centralized JSON-type aliases and errno helpers for consistent error handling across modules. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jess Yaunches <jyaunches@nvidia.com>
Summary
Follow-up to PR #2422 (
refactor(types): tighten repo-wide type boundaries). Addresses the review warnings and suggestions from triage.Changes
1. Shared
isErrnoException/isPermissionError—src/lib/errno.tsPR #2422 removed all
@ts-nocheckmarkers, which required each module to define its ownisErrnoException+ErrnoLiketype locally. This resulted in 6 slightly different copies acrossconfig-io,credentials,http-probe,onboard,onboard-session, andregistry.This PR extracts a single canonical version into
src/lib/errno.tsthat:unknownso callers never need aninstanceof Errorpre-castcodeanderrnoproperties (covering all Node.js error shapes)isPermissionErrorfor the common EACCES/EPERM guardThis also simplifies many catch blocks that previously did
error instanceof Error && isErrnoException(error)— the redundantinstanceof Errorcheck is now handled inside the shared function.2. Shared JSON recursive types —
src/lib/json-types.tsPR #2422 introduced identical Scalar/Value/Object type triples in multiple modules:
LooseScalar/LooseValue/LooseObjectinonboard.tsandagent-onboard.tsPolicyScalar/PolicyValue/PolicyObjectinpolicies.tsSessionJsonPrimitive/SessionJsonValue/UnknownRecordinonboard-session.tsThis PR extracts canonical
JsonScalar/JsonValue/JsonObjecttypes intosrc/lib/json-types.ts. Each module re-aliases them under its domain names for readability.3.
Reflect.get/Reflect.setconvention commentAdds a clarifying comment at the first usage site (
usage-notice.ts) explaining whyReflect.getis preferred overas Record<…>casts throughout the codebase — it avoids widening the target type and satisfiesno-unsafe-member-accesslint rules.4.
ws-proxy-fix.tsbehavioral guard documentationDocuments the
!hostnull guard in the Discord WebSocket tunnel path, explaining that the previous code would have attempted a tunnel with an undefined host (which would fail downstream anyway). The guard now explicitly falls through to the originalhttps.requestunchanged.Type of Change
Verification
tsc -p tsconfig.cli.json --noEmitpassesnpm testpasses (only pre-existing failures in install-preflight and ssrf-parity)errno.tsmodule (15 test cases)make docsbuilds without warnings (doc changes only)AI Disclosure
Signed-off-by: Jess Yaunches jyaunches@nvidia.com
Summary by CodeRabbit
Bug Fixes
Tests
Documentation
Chores