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

nits and fixes #416

Merged
merged 1 commit into from
Nov 21, 2023
Merged

nits and fixes #416

merged 1 commit into from
Nov 21, 2023

Conversation

cfbao
Copy link
Member

@cfbao cfbao commented Nov 20, 2023

No description provided.

@github-actions github-actions bot added language/csharp size/M A medium-sized PR. labels Nov 20, 2023
Comment on lines +4 to +5
private static readonly string BMX_DIR = Path.Join(
Environment.GetFolderPath( Environment.SpecialFolder.UserProfile ),
Copy link
Member Author

Choose a reason for hiding this comment

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

USER_HOME_DIR and BMX_DIR are only used inside this static class to define other paths now, so they should be private or inlined.

@@ -1,11 +1,14 @@
namespace D2L.Bmx;

internal static class BmxPaths {
public static readonly string USER_HOME_DIR = Environment.GetFolderPath( Environment.SpecialFolder.UserProfile );
public static readonly string BMX_DIR = Path.Join( USER_HOME_DIR, ".bmx" );
public static readonly string CACHE_DIR = Path.Join( BMX_DIR, "\\cache" );
Copy link
Member Author

Choose a reason for hiding this comment

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

the point of Path.Join is that we don't need to worry about path separators.
including a backslash also results in incorrect behaviour on POSIX systems, where backslash can be part of a valid directory name.
@alex-fang0

Comment on lines -222 to -224
File.Delete( Path.Join( BmxPaths.BMX_DIR, "awsCredsCache" ) );
File.Delete( Path.Join( BmxPaths.BMX_DIR, "sessions" ) );
File.Delete( Path.Join( BmxPaths.BMX_DIR, "update_check" ) );
Copy link
Member Author

Choose a reason for hiding this comment

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

awsCredsCache and update_check are never released, so there's no need to handle them.

Moving (rather than deleting) sessions keeps user's old cached session, which is better UX.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, what does 'released' mean here? I'm having trouble finding it on google because of the word 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean they're not in bmx v3.0.0, so "the people" never got them.

Copy link
Contributor

@gord5500 gord5500 Nov 20, 2023

Choose a reason for hiding this comment

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

Ah, I see now. Thanks Chenfeng

File.Move( BmxPaths.SESSIONS_FILE_LEGACY_NAME, BmxPaths.SESSIONS_FILE_NAME );
}
} catch( Exception ex ) {
throw new BmxException( "Failed to initialize BMX directory (~/.bmx)", ex );
Copy link
Member Author

Choose a reason for hiding this comment

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

Don't swallow errors on directory init, because our file logic in the rest of the codebase now assumes the necessary directories always exist. If there's an error here and is ignored, we may encounter an unexpected error down the line, which results in non-descriptive error message for the user.

This does mean that we run the slight risk of erroring out on failing to move the sessions file, when it could be ignored. But that's a much smaller concern to me. If there's an error in moving that file, there's probably something odd about the user's filesystem and may be worth investigating anyway.

},
System.CommandLine.Invocation.MiddlewareOrder.ExceptionHandler + 1

await UpdateChecker.CheckForUpdatesAsync( configProvider.GetConfiguration() );
Copy link
Member Author

Choose a reason for hiding this comment

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

move the update checker below directory init, so we can assume existence of standard BMX directories inside of it.

Comment on lines +233 to +236
// The default order for new middleware is after the middleware for `--help` & `--version` and can get short-circuited.
// We want our middleware (especially update checks) to almost always run, even on `--help` & `--version`,
// so we specify a custom order just after the exception handler (which is way before `--help` & `--version`).
order: MiddlewareOrder.ExceptionHandler + 1
Copy link
Member Author

@cfbao cfbao Nov 20, 2023

Choose a reason for hiding this comment

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

I couldn't recall exactly why we specified a middleware order here, and had to check Slack history, so it's worth explaining in a comment.

@cfbao cfbao marked this pull request as ready for review November 20, 2023 19:20
@cfbao cfbao requested a review from a team as a code owner November 20, 2023 19:20
@cfbao cfbao merged commit 8c28c21 into main Nov 21, 2023
9 checks passed
@cfbao cfbao deleted the cbao/nits branch November 21, 2023 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language/csharp size/M A medium-sized PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants