Skip to content

handle exception when dependencies are not installed #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

blasdfaa
Copy link

resolves #91

Copy link

changeset-bot bot commented Apr 19, 2025

⚠️ No Changeset found

Latest commit: a9d1fcb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@blasdfaa
Copy link
Author

@illright could you please review?

Copy link
Member

@illright illright left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this issue! I like the overall direction of the solution, left some comments to align it more to how the current components (linter, CLI, features) interact.

Could you also add a patch changeset for this feature?

Comment on lines +28 to +33
console.error('\n\x1b[31mError: Unable to find Nuxt TypeScript configuration\x1b[0m')
console.error('\nThis appears to be a Nuxt project, but the TypeScript configuration files are missing.')
console.error('These files are auto-generated when you install dependencies.')
console.error('\nTo fix this:')
console.error('1. Run \x1b[36mnpm install\x1b[0m or \x1b[36myarn\x1b[0m or \x1b[36mpnpm install\x1b[0m')
console.error('2. Then run Steiger again\n')
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: we have picocolors installed, let's use that instead of raw ANSI codes for text coloring for better readability

devDependencies?: Record<string, string>
}

const readPackageJSON = (path: string) => JSON.parse(readFileSync(join(path, 'package.json'), 'utf-8')) as PackageJson
Copy link
Member

Choose a reason for hiding this comment

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

issue: it might be the case that package.json is in one of the parent folders, not necessarily the one where Steiger was run

suggestion: let's use empathic to locate the package.json file:

import * as find from 'empathic/find'
find.up('package.json', { cwd: path })

}

export function handleError(error: unknown, context: ErrorContext): never {
const isHandled = [checkNuxtConfigError].some((checker) => checker(error, context))
Copy link
Member

Choose a reason for hiding this comment

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

praise: interesting architecture! I'm not sure how many more of those there will be, but thanks for building with extensibility in mind :)

}
}

export function handleError(error: unknown, context: ErrorContext): never {
Copy link
Member

Choose a reason for hiding this comment

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

issue: it takes a bit of code reading to understand what this function does, especially since its return type is never

suggestion: let's add a docstring that explains that this function attempts to gracefully handle the error using one of the known error checkers, and rethrows it if it can't

const isHandled = [checkNuxtConfigError].some((checker) => checker(error, context))

if (isHandled) {
process.exit(1)
Copy link
Member

Choose a reason for hiding this comment

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

issue: not a big fan of handling process exits from within the code of the linter app. This is more the responsibility of the CLI — to print the error message and exit with an error code

suggestion: maybe we can redo this function to instead throw a known error, and also export a separate function that would handle the error message printing? The way I see it working is like this:

  1. The linter code encounters a tsconfig error
  2. The handleError function recognizes that this is a Nuxt-related issue
  3. The linter code throws a KnownIssueError (or something) to the caller, in this case, cli.ts
  4. The CLI uses the the code from the handle-error feature to print some guidance
  5. The CLI returns with a unique error code

In this solution, I think it would also make sense to make handle-error a folder, and maybe also give it a more descriptive name like detect-known-exceptions

Copy link
Member

Choose a reason for hiding this comment

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

suggestion: let's remove this and some other unnecessary template files: README.md, robots.txt

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.

Uncaught exception when dependencies are not installed
2 participants