Skip to content
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

chore: bump minimum required Deno version to 1.46.0 and cleanup #332

Merged
merged 46 commits into from
Oct 21, 2024

Conversation

magurotuna
Copy link
Member

@magurotuna magurotuna commented Oct 16, 2024

This commit bumps the minimum required Deno version to 1.46.0 and cleanups the code mainly to deal with deprecated Deno APIs.

Fixes #328

@magurotuna
Copy link
Member Author

Blocked by denoland/deno_emit#167 as deployctl relies on @deno/emit to transpile TS code into JS so it can be run as GitHub Actions action.

@magurotuna magurotuna changed the title WIP: clean up deps and get deployctl to pass typecheck on Deno 2.0 chore: bump minimum required Deno version to 2.0.0 and cleanup Oct 18, 2024
@magurotuna magurotuna changed the title chore: bump minimum required Deno version to 2.0.0 and cleanup chore: bump minimum required Deno version to 1.46.0 and cleanup Oct 18, 2024
Comment on lines -8 to -21
// deno-lint-ignore no-explicit-any
export function isTerminal(stream: any) {
if (
semverGreaterThanOrEquals(
semverParse(Deno.version.deno),
semverParse("1.40.0"),
)
) {
return stream.isTerminal();
} else {
// deno-lint-ignore no-deprecated-deno-api
return Deno.isatty(stream.rid);
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

For reviewers: isTerminal method on various stream types is available on 1.40.0+ and our minimum required Deno version is now 1.46.0. We don't have to polyfill anymore.

@magurotuna magurotuna marked this pull request as ready for review October 18, 2024 06:06
Copy link
Member

@arnauorriols arnauorriols left a comment

Choose a reason for hiding this comment

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

Added some comments

.github/workflows/ci.yml Outdated Show resolved Hide resolved
src/error.ts Outdated
function stringifyError(err: Error): string {
const cause = err.cause === undefined
? ""
: `Caused by ${stringify(err.cause)}`;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add the new line in here, this way we don't get an empty line if there's no cause.

Having said that, being a CLI tool, deployctl is sensible to changes in the formatting of the error messages. I'm a bit concerned that adding this newline will break the formatting here and there inadvertently. Maybe we could use parenthesis (${cause}) instead of new line \n${cause}?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you elaborate a bit more on why CLI tools are sensible to the change of error message formats?

Maybe we could use parenthesis (${cause}) instead of new line \n${cause}?

Parenthesis sounds good, but the next problem is that cause itself might contain newline characters in it. I'll try to replace them (if any) with white spaces.

Copy link
Member

@arnauorriols arnauorriols Oct 18, 2024

Choose a reason for hiding this comment

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

There are places where the error is not fatal, and should be shown to the user as part of the regular output. If the error has multiple lines it breaks the output layout. One example is #332 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes lots of sense. I'll create another function to stringify errors in a simple, one-line format rather than full verbose ones so we can use it in non-fatal places.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now stringify function gets verbose option which defaults to false. If an error is printed when the deployctl program keeps running, simple message is displayed. Otherwise i.e. when the program exits right after the error message is printed, verbose message is generated.

@@ -76,7 +77,7 @@ async function provision(): Promise<string> {
wait("").start().warn(
"Unexpected error while trying to open the authorization URL in your default browser. Please report it at https://github.com/denoland/deployctl/issues/new.",
);
wait({ text: "", indent: 3 }).start().fail(error.toString());
wait({ text: "", indent: 3 }).start().fail(stringifyError(error));
Copy link
Member

Choose a reason for hiding this comment

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

Can you check if this change breaks the output format? IIRC it was sensible to multiline error messages.

Copy link
Member Author

Choose a reason for hiding this comment

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

If an error is formatted in a multi-line format, it is printed like this:

CleanShot 2024-10-18 at 20 29 43@2x

This error instance is created as follows:

    const e1 = new Error("This is\na multiline\nerror");
    const e2 = new Error("e2", { cause: e1 });
    throw e2;

I am not sure if I understand your concern, but does this look concerning to you?

Copy link
Member

@arnauorriols arnauorriols Oct 18, 2024

Choose a reason for hiding this comment

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

It's purposedly indentated and kept in a single line because it is not a hard error, the program continues. If the error breaks this identation then it breaks the output layout.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now stringifyError(error) returns a simple one-line error message while stringifyError(error, { verbose: true }) generates a full detailed output.

@arnauorriols
Copy link
Member

Also make sure to update the README with the new minimum version

Copy link
Member

@arnauorriols arnauorriols left a comment

Choose a reason for hiding this comment

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

LGTM!

@magurotuna magurotuna merged commit bd19482 into denoland:main Oct 21, 2024
11 checks passed
@magurotuna magurotuna deleted the magurotuna/deno-isatty branch October 21, 2024 11:49
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.

deployctl does not work with Deno 2.0 RC version
2 participants