Repository navigation
Conversation
|
Yeah I tried to figure out how to have those code paths be explored by the unit tests but I failed. Apart from 'failed to load file (is a directory)' it seems that none of the corresponding paths were being tested initially. @laurmaedje any suggestions on how to proceed ? Is it acceptable for this logic to remain untested as it was ? |
|
It's okay to skip tests for now. We'll add CLI tests at some point in the future. |
|
Alright, thanks. Then I'm happy with the current state of this |
I think we should do that, the error messages can be fairly long in these cases, if we move parts into the hints they get a little more digestible in my opinion. The first hint could be adjusted according to the actual failure (namespace missing, package missing, file within missing, etc.). I think, generally, what is placed in parentheses can almost always be moved to a hint. |
tingerrr
left a comment
There was a problem hiding this comment.
I've noted a few things down, thanks for taking my suggestions into consideration!
| "the registry at {registry} provides up to version {version}" | ||
| ), | ||
| ] | ||
| } else { |
There was a problem hiding this comment.
Does the else branch here happen realistically, for typst init? I'd assume that, if there is no version for a package, then the package does not exist, in which case it should emit the NotFound variant.
There was a problem hiding this comment.
Since the file structure is namespace/package/version, I see a difference between NotFound (namespace/package doesn't exist) vs VersionNotFound(None) (namespace/package exists but is empty),
and that was the logic behind keeping it as a VersionNotFound.
There was a problem hiding this comment.
Ah, I only considered it originating from the registry, good point, although the package path existing with no version directories in it is more likely an indicator for an aborted downloading process. The error message makes it seems like the registry returned a package with no versions (which should be impossible).
|
Urgh. Ignore that, I made a mistake while rebasing. |
989bfcc to
2d8f7f4
Compare
|
Alright, I'm back to this. Regarding the utf-8 error requiring a path: every call site has a path accessible. I'm not sure if
I assume the currently failing tests are just due to small changes is the wording of some messages, it'll be a quick fix. |
|
Oh. No idea how to solve that. |
Ah, that'll require some change to the test runner, I think there are two obvious solutions:
I would go with the former because it gives greater control when these characters should be substituted, and it can be re-used for other things too. Though I'm not sure about the syntax for it. |
|
The test runner already has a hack for this, but it appears that it only happens for the message, not the hints: Lines 231 to 235 in 3d64f7b |
|
The hack for keeping |
Yes it's quite annoying really, I have not yet found a nice way to make unit tests behave nicely when they compare paths. In other projects, I've thought about adding some sort of compile-time flag to switch paths to a normalized form for unit tests regardless of platform. It is the only approach I could think of that doesn't seem like a hack, but it's quite the scope creep and extra work for path printing. Should they just go with doing the same hack for annotations for now? |
That would be okay with me. Would be good to factor it out into a function though. |
|
There will be an additional hack needed though.
I'll think of a way to not make it too ad-hoc. |
|
Let me know if you figure something nice out, and I'll use it in my test suites too. |
2c1b721 to
8be061e
Compare
|
So in principle this approach works. |
|
@Vanille-N please excuse the long radio silence. I was primarily shying away from landing this because I wasn't confident in the changes in the public API. However, with #7555 the public API will change quite a bit anyway, so it's a good opportunity to take another stab at this. My plan was to re-review and reconsider the public API changes once that PR has landed and this PR here is rebased. |
|
Alright. Then I'll ignore merge conflicts until #7555 lands and rebase all at once. |
|
I tried to have a look at the new API, and it seems it's going to be a challenge to get a concrete path from a |
|
In principle, the API should be roughly isomorphic to the old one ( |
|
#7710 has landed, so we should now be ready to proceed here.
I'm not sure what exactly you mean, maybe you can elaborate. Also, feel free to ping me on Discord to discuss this. |
|
Hi @Vanille-N, are you still interested in working on this? If not, that's also totally fine, but then I would close the PR. |
|
Ah, yeah sorry for letting this get stale. What happened is that the merge conflicts were too big to rebase, to the point that the final result was a bit nonsensical. This would have to be redone from scratch. I'm still interested in solving this issue eventually, but it won't be this PR and probably not right now. |
I talked about this a few hours ago on a half-related issue, and here I am!
Several of Typst's error messages in the case of a file not found or package not found are hard to debug because the error message does not specify the path that was searched.
Combined with dynamic loading of files or the conventions as to where the package directory is, this results in messages such as
or
which are unhelpful.
This PR changes the error messages in the following cases:
@localnamespace doesn't existpackage in
@localdoesn't existpackage in
@localis missing this versionpackage in
@localhas no manifestpackage in
@previewdoesn't existpackage in
@previewis missing this versionaccess denied to file
Minor changes to functions and types
download_packageshould return thePathBufin case of success, it spares us oneexistscheck.FileErrornow contain somePathBufs to remember which file they tried to accessMajor change to trait
In the previous version the path from
PackageError(what the function that tries to load a package returns) toSourceDiagnostic(errors that can be printed with a span) was through the following detailed chain:impl Display for PackageErrorimpl Display for FileErrordefers toPackageError: Displayimpl From<FileError> for EcoStringinvokesFileError: Displayimpl Into<EcoString> for FileErrorgenerated fromEcoString: From<FileError>impl<T, S> At<T> for Result<T, S> where S: Into<EcoString>This path means that
FileErrorand thus by extensionPackageErrorcan only provide a single line's worth of error message.In this PR the new path is
impl Display for PackageErrorprovides the headerimpl Display for FileErrordefers to the abovewrite_diagnostics(self) -> EcoVec<EcoString>inimpl PackageErrorprovides the hintswrite_diagnostics(self) -> EcoVec<EcoString>inimpl FileErrordefers to the aboveimpl ErrAt for FileError(new trait) invokes bothFileError: DisplayandFileError::write_diagnosticsand returns aSourceDiagnosticIf you have a better solution in mind I can adapt, or if this is fine then I'll just add a bit of documentation.