Skip to content

Add central CLI error handler and exit codes#11

Merged
paulius-krutkis-dcd merged 6 commits into
mainfrom
a7/exit-codes
Jun 8, 2026
Merged

Add central CLI error handler and exit codes#11
paulius-krutkis-dcd merged 6 commits into
mainfrom
a7/exit-codes

Conversation

@paulius-krutkis-dcd

@paulius-krutkis-dcd paulius-krutkis-dcd commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Centralize CLI error handling with consistent exit codes (0–7) across scrape, auth, and top-level failures.
  • Switch to published @decodo/sdk-ts from npm and simplify CI/dev setup.
  • Target groups with group: "None" in the bundled schema are outscoped to sdk-ts — the CLI reads getTargetMeta(target).group directly with no inference layer. Fix groups in the SDK, publish, then bump the CLI dependency.

Test plan

  • pnpm test
  • Spot-check error exits: missing auth, validation failure, rate limit

@paulius-krutkis-dcd paulius-krutkis-dcd changed the base branch from ndjson-streaming to main June 8, 2026 05:52
paulius-krutkis-dcd and others added 4 commits June 8, 2026 08:54
Route command failures through a shared handler so every error type exits consistently and keeps stdout clean for scripted usage. This also aligns SDK validation/rate-limit failures with explicit exit codes expected by downstream automation.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Simplified the error handling logic in `handleCliError` by consolidating condition checks.
- Removed the `handleScrapeError` function and directly utilized `handleCliError` in the scrape execution flow.
- Updated tests to reflect changes in error handling, ensuring consistent behavior across different error types.
- Enhanced test cases by directly instantiating error objects instead of using a custom error creation function.
…ify build process

- Changed the dependency for @decodo/sdk-ts from a local file reference to version 2.1.1 in package.json and pnpm-lock.yaml.
- Removed the prebuild and build:sdk-ts scripts, streamlining the pretest process to only run pnpm build.
- Updated README to reflect the new development setup without the sibling checkout requirement for sdk-ts.
- Adjusted CI workflow to eliminate unnecessary checkout steps for sdk-ts, improving efficiency.
- Added a new service, `resolveTargetGroup`, to determine the group of targets based on schema metadata and naming conventions.
- Updated `createCodegenTargetCommands` and `createListTargetsCommand` to utilize the new group resolution logic, improving command descriptions.
- Enhanced tests to ensure that "None" is not exposed as a command description group and to validate the new group resolution functionality.
- Updated the build script to use a single TypeScript configuration for building.
- Removed the CommonJS build configuration and associated renaming script.
- Adjusted the `RootOptions` interface to reorder properties for consistency.
- Cleaned up error handling tests by replacing custom error creation with direct instantiation.
@paulius-krutkis-dcd paulius-krutkis-dcd mentioned this pull request Jun 8, 2026
9 tasks
Comment on lines +44 to +56
if (target.startsWith("universal")) {
const universalGroup = schema.getTargetMeta("universal")?.group;
if (isValidGroup(universalGroup)) {
return universalGroup;
}
}

if (target.includes("ecommerce")) {
const ecommerceGroup = schema.getTargetMeta("ecommerce")?.group;
if (isValidGroup(ecommerceGroup)) {
return ecommerceGroup;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would remove this special handling of groups - the sdk is the source of truth

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the CLI-side group inference — will fix missing groups in sdk-ts instead, then bump the dependency here.

Comment on lines +9 to +28
function inferGroupFromPrefix(
schema: DecodoSchema,
target: string
): string | undefined {
const prefix = target.split("_")[0];
if (prefix.length === 0) {
return;
}

for (const other of schema.listTargets()) {
if (other === target || !other.startsWith(`${prefix}_`)) {
continue;
}

const otherGroup = schema.getTargetMeta(other)?.group;
if (isValidGroup(otherGroup)) {
return otherGroup;
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better option would be to enforce a group for each target, that way we can get rid of this magic guessing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Dropped prefix inference from this PR; enforcing groups in sdk-ts.

…nd logic

- Eliminated the `resolveTargetGroup` service, integrating its functionality directly into command creation.
- Updated `createCodegenTargetCommands` and `createListTargetsCommand` to use `schema.getTargetMeta` for group resolution, enhancing command descriptions.
- Removed related tests for `resolveTargetGroup` and ensured that "None" is not exposed in command descriptions.
@paulius-krutkis-dcd paulius-krutkis-dcd merged commit 77250df into main Jun 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants