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

Authentication #37

Merged
merged 7 commits into from
Jul 15, 2022
Merged

Authentication #37

merged 7 commits into from
Jul 15, 2022

Conversation

enderger
Copy link
Contributor

@enderger enderger commented Jul 11, 2022

Intro

This integrates Hydra with Theseus to provide what can be described as the bare minimum requirement for a non-cracked launcher.

Closes #4

Tasks

  • Use Hydra to allow users to log into Minecraft before launching the game
  • Store the resulting token so that it can be reused without opening many browser windows
  • Add a system for managing users using the database
  • Implement user management in the CLI

@enderger enderger marked this pull request as ready for review July 12, 2022 03:38
Copy link
Member

@Geometrically Geometrically left a comment

Choose a reason for hiding this comment

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

It looks good, but I'm really concerned with the tracer macros. I feel like there could be a way better system for it, and adding it to every function in the library seems pretty annoying

/// To run this, you need to first spawn this function as a task, then
/// open a browser to the given URL and finally wait on the spawned future
/// with the ability to cancel in case the browser is closed before finishing
#[tracing::instrument]
Copy link
Member

Choose a reason for hiding this comment

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

are these macros needed everywhere with this lib?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only on functions which need to be known about in the spantrace. Unfortunately, since async Rust doesn't have any real consistent stack to trace usefully, we need to use the macro to determine where we are in actual control flow.

#[derive(thiserror::Error, Debug)]
pub enum Error {
pub enum ErrorKind {
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of this name change? Most Rust libs use Error, and I think we should stick to that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is now integrated into the actual error type, which captures it and a spantrace so it can be traced back further than where application code is invoked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there were a better solution for async, the authors of the Tokio runtime probably would have used it as the main way to trace errors in their own runtime (after all, Tokio is the one who authored the tracing library and is using it in their console debugger).

Copy link
Member

Choose a reason for hiding this comment

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

IMO the old Error should be called Error because it's the direct library error. The other error should be TracableError or something of the sorts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, everywhere uses this kind of convention, backtraces are captured using a similar pattern usually.

theseus/src/state/mod.rs Outdated Show resolved Hide resolved
@@ -52,4 +69,35 @@ pub enum Error {
OtherError(String),
}

#[derive(Debug)]
pub struct Error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the purpose of this name change? Most Rust libs use Error, and I think we should stick to that

@Geometrically - This is the new error type, which wraps ErrorKind with the spantrace so that errors can be traced further than the call site.

@Geometrically
Copy link
Member

To be honest, I don't like the whole idea of tracing/implementing this library. I'm not sure what issues it solves. It adds a lot of extra code, and I don't think this will go well when we have to implement it in tauri

@enderger
Copy link
Contributor Author

enderger commented Jul 14, 2022

To be honest, I don't like the whole idea of tracing/implementing this library. I'm not sure what issues it solves. It adds a lot of extra code, and I don't think this will go well when we have to implement it in tauri

It allows errors to know where they came from, in async the stack is not very helpful in tracing errors since each task is managed by an executor which is detached from the call stack (this is the whole reason behind the need to move values into spawned tasks, since tasks can’t store data that could be popped off of the call stack before it finishes), thus requiring some other way to track position in control flow.

As an example, this is an error without tracing
image

And with tracing, it is:
image

Enabling the backtrace gives something almost completely useless due to the aforementioned stack decoupling, so control flow needs to be tracked some other way. The macros provide a convenient way to attach a span to a function (though doing so manually is possible with tracing, allowing large functions to be split further for error tracing purposes), provides a way to only trace what functions are useful to know about, and allows you to customize how error reporting is handled. Tracing allows for the extraction of spans from types which track them, so the frontend could pretty easily extract the info from errors to provide usable error messages that can actually be used to find backend bugs.

Copy link
Member

@Geometrically Geometrically left a comment

Choose a reason for hiding this comment

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

lgtm! sorry for the hassle- was a little confused about the backtrace stuff

@Geometrically Geometrically merged commit b223dc7 into master Jul 15, 2022
@Geometrically Geometrically deleted the feature/auth branch July 15, 2022 15:39
@enderger enderger restored the feature/auth branch July 18, 2022 20:59
@enderger enderger deleted the feature/auth branch July 18, 2022 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Launcher: Support Microsoft account authentication
2 participants