Skip to content

Make "Couldn't import file" more clear. Potential bug #374

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
artpaym opened this issue May 13, 2025 · 11 comments
Open

Make "Couldn't import file" more clear. Potential bug #374

artpaym opened this issue May 13, 2025 · 11 comments
Assignees

Comments

@artpaym
Copy link

artpaym commented May 13, 2025

Make "Couldn't import file" error more clear.

Currently it just says it failed to import a file, for example:

sjsonnet.Error: Couldn't import file: "../../somefolder/somefile.jsonc"
    at [Import].(src/...)
    ...

In the error message, add details on:

  • where it was trying to get the file (i.e. how it resolved the parent folder syntax"../../" to the absolute path)
  • why there (i.e. what was considered as the current path)

I suspect there is some bug with paths resolution, because "jsonnet" processes the same files just fine (and sjsonnet as well, but only when full absolute path is given).

I can't reproduce the bug itself, because this is a huge project, and on a smaller example sjsonnet works file, so I don't understand what's the issue exactly.

@He-Pin
Copy link
Contributor

He-Pin commented May 13, 2025

@artpaym Are you using sjsonnet at work too?

@stephenamar-db stephenamar-db added this to the v0.5.1 milestone May 15, 2025
@stephenamar-db
Copy link
Collaborator

I'm merging #385 and it will ship with 0.5.1.
@artpaym tell me if that's enough to help debug your issue.

@stephenamar-db stephenamar-db removed this from the v0.5.1 milestone May 15, 2025
@He-Pin
Copy link
Contributor

He-Pin commented May 16, 2025

@artpaym 0.5.1 has just been released, can you help test it?

@artpaym
Copy link
Author

artpaym commented May 21, 2025

@He-Pin @stephenamar-db thanks, --debug-importer brought some clarity.

Let me describe what I see.

I'm running sjsonnet from a WSL folder which is also managed by Nix (in case it matters): /home/artem/work/project/.

The command is:

./sjsonnet-0.5.1-linux-x86_64 --tla-str a=1 --tla-str b=2 --tla-code message="$(cat ./subfolder/message.json)" ./subfolder/src/mapper.jsonnet

so I'm passing a couple of tlas and passing some jsonnet source file from a subfolder.

The output is (I changed folder names):

...
[import ../../xxx/yyy/zzz.jsonnet] candidate /home/artem/work/project/subfolder/src/foo/bar/xxx/yyy/zzz.jsonnet
[import ../../xxx/yyy/zzz.jsonnet] none of the candidates exist

sjsonnet.Error: Couldn't import file: "../../xxx/yyy/zzz.jsonnet"
    at [Import].(subfolder/src/foo/bar/index.jsonnet:9:8)
    ...
    at [BinaryOp +].(subfolder/src/mapper.jsonnet:44:7)

the body of subfolder/src/foo/bar/index.jsonnet (inside which the "import" fails) is:

{
  ...
  someField: import '../../xxx/yyy/zzz.jsonnet',
  ...
}

Relative to that zzz.jsonnet file, the ../../ in someField import should resolve to subfolder/src/, but apparently it doesn't happen for some reason, so sjsonnet tries to find that file path under the same folder where zzz.jsonnet is located itself (subfolder/src/foo/bar/): /home/artem/work/project/subfolder/src/foo/bar/xxx/yyy/zzz.jsonnet

Instead, correct location should be /home/artem/work/project/subfolder/src/xxx/yyy/zzz.jsonnet.

Does it help?


@He-Pin yes we're using it at work, I'm looking for jrsonnet alternatives which we're currently calling as a standalone binary from a Java app. If sjsonnet has good speed, I'd want to try running it as a library from Java app (afaik it's possible) for even better speeds. For that I wanted to create a separate ticket as I'm confused how to do that.

@stephenamar-db
Copy link
Collaborator

I'm trying to reproduce.

Can you clarify what is in ./subfolder/src/mapper.jsonnet?

How is foo/bar/index.jsonnet imported?

Does the directory structure look like?

./subfolder/src/mapper.jsonnet
./subfolder/src/foo/bar/index.jsonnet
./subfolder/src/xxx/yyy/zzz.jsonnet

@stephenamar-db
Copy link
Collaborator

stephenamar-db commented May 21, 2025

There's a problem with native:

Scala Native:

~/sjsonnet % out/sjsonnet/native/3.3.6/nativeLink.dest/out --debug-importer ./subfolder/mapper.jsonnet 
[import foo/bar/index.jsonnet] candidate /Users/stephen.amar/sjsonnet/subfolder/foo/bar/index.jsonnet
[import foo/bar/index.jsonnet] /Users/stephen.amar/sjsonnet/subfolder/foo/bar/index.jsonnet is selected as it exists
[import ../../xxx/yyy/zzz.jsonnet] candidate /Users/stephen.amar/sjsonnet/subfolder/foo/bar/xxx/yyy/zzz.jsonnet
[import ../../xxx/yyy/zzz.jsonnet] none of the candidates exist
sjsonnet.Error: Couldn't import file: "../../xxx/yyy/zzz.jsonnet"
    at [Import].(subfolder/foo/bar/index.jsonnet:2:8)

Scala JVM:

~/sjsonnet % out/sjsonnet/jvm/3.3.6/assembly.dest/out.jar --debug-importer ./subfolder/mapper.jsonnet                                             
[import foo/bar/index.jsonnet] candidate /Users/stephen.amar/sjsonnet/subfolder/foo/bar/index.jsonnet
[import foo/bar/index.jsonnet] /Users/stephen.amar/sjsonnet/subfolder/foo/bar/index.jsonnet is selected as it exists
[import ../../xxx/yyy/zzz.jsonnet] candidate /Users/stephen.amar/sjsonnet/subfolder/xxx/yyy/zzz.jsonnet
[import ../../xxx/yyy/zzz.jsonnet] /Users/stephen.amar/sjsonnet/subfolder/xxx/yyy/zzz.jsonnet is selected as it exists
{
   "foo": "foo"
}

@stephenamar-db
Copy link
Collaborator

I filed a bug with os-lib

@stephenamar-db stephenamar-db self-assigned this May 21, 2025
@He-Pin
Copy link
Contributor

He-Pin commented May 21, 2025

We are using sjsonnet as a library from Spring app, which works well, hope we can share something.

@He-Pin
Copy link
Contributor

He-Pin commented May 21, 2025

Maybe a bug in scala native library ?

@artpaym
Copy link
Author

artpaym commented May 21, 2025

@stephenamar-db ./subfolder/src/mapper.jsonnet imports another file where via a chain of other imports eventually in turn foo/bar/index.jsonnet gets imported who in turn fails on ../../xxx/yyy/zzz.jsonnet import. But looks like you've found potential issue, great, thanks!

@He-Pin sounds promising, then maybe you can check this one #405

@He-Pin
Copy link
Contributor

He-Pin commented May 22, 2025

Does it mean a call to java.nio.file.Path#normalize is missing, or the implementation in scala-native is wrong?

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

No branches or pull requests

3 participants