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

Not_found exception thrown in Camomile/internal/database.ml #44

Open
rwmjones opened this issue Nov 8, 2017 · 7 comments
Open

Not_found exception thrown in Camomile/internal/database.ml #44

rwmjones opened this issue Nov 8, 2017 · 7 comments
Milestone

Comments

@rwmjones
Copy link

rwmjones commented Nov 8, 2017

ocaml-gettext uses camomile. However the latest version of Camomile doesn't work - a Not_found exception gets thrown deep inside camomile.

An easy reproduce in ocaml-gettext is to simply run:

OCAMLRUNPARAM=b ../_build/bin/ocaml-gettext --action compile --compile-output fr.mo fr.po
Fatal error: exception Not_found
Raised at file "Camomile/internal/database.ml", line 50, characters 52-67
Called from file "Camomile/internal/unidata.ml" (inlined), line 187, characters 2-46
Called from file "Camomile/public/uCharInfo.ml", line 307, characters 2-30
Called from file "camomileLibrary.mlp", line 204, characters 22-44
Called from file "camomileLibrary.mlp", line 168, characters 0-1023
Called from file "Camomile/camomileLibraryDefault.ml", line 37, characters 18-46
@rwmjones
Copy link
Author

rwmjones commented Nov 8, 2017

let read dir suffix reader key =
  let fname = escape key in
  let path = Filename.concat dir (fname ^ "." ^ suffix) in
  let c = try open_in_bin path with Sys_error _  -> raise Not_found in (** here **)
  let v = reader c in
  close_in c;
  v

I can see in the code where it's thrown, but not why.

@rwmjones
Copy link
Author

rwmjones commented Nov 8, 2017

Looking at it a bit more, I see this is some kind of configuration/installation problem:

20282 openat(AT_FDCWD, "/usr/share/camomile/database/general_category.mar", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

$ ll /usr/share/camomile/database/general_category.mar
lrwxrwxrwx. 1 root root 61 Nov  8 17:17 /usr/share/camomile/database/general_category.mar -> ../../../../../default/Camomile/database/general_category.mar

Damn, I wish people wouldn't use jbuilder ...

@rwmjones
Copy link
Author

rwmjones commented Nov 8, 2017

OK I fixed it by dereferencing the symlinks instead of copying them. Could we improve the error here? If the database files don't exist it shouldn't throw Not_found, it would be better if it failed hard with an informative error.

@rgrinberg
Copy link
Collaborator

Note that some code paths rely on actually catching this Not_found error. So we better be careful about changing this.

@yoriyuki
Copy link
Owner

Ok, I see four problems:

  1. Make error messages more informative. (we can arbitrary define exceptions but if there is a standard way then it's better)
  2. somehow symlinks don't work. why?
  3. jbuilder symlinks not copies the data files. Data files are just marshalled data, so it could be potentially dangerous.
  4. ocaml.gettext needs needs to read general_category.mar, which is most likely useless for this app. In future (v 2.0?), we need to break up Camomile to smaller packages.

@rgrinberg
Copy link
Collaborator

rgrinberg commented Nov 11, 2017 via email

@rwmjones
Copy link
Author

  1. somehow symlinks don't work. why?
  2. jbuilder symlinks not copies the data files. Data files are just marshalled data, so it could be potentially dangerous

What was happening is that we don't have opam-installer and jbuilder can't install without it, so I was just copying the symlinks, but didn't use -L so it copied the symlinks rather than the files.

However there is still a problem with camomile:

  let c = try open_in_bin path with Sys_error _  -> raise Not_found in

If that open_in_bin function fails for any reason other than file not found (eg. broken symlink, I/O error) then the true error is hidden. The check should be specifically for file not found (mapped to Not_found), any other error should be rethrown verbatim or possibly exit hard.

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