Skip to content

Commit

Permalink
Remove unused stuff from Bsb_exception (#7130)
Browse files Browse the repository at this point in the history
* Remove unused bsb exception types

* Bsb_exception.Package_not_found: removed unused param
  • Loading branch information
cknitt authored Oct 26, 2024
1 parent 60b99ea commit 54c5459
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 66 deletions.
33 changes: 7 additions & 26 deletions compiler/bsb/bsb_exception.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,40 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

type error =
| Package_not_found of Bsb_pkg_types.t * string option (* json file *)
| Package_not_found of Bsb_pkg_types.t
| Json_config of Ext_position.t * string
| Invalid_json of string
| Invalid_spec of string
| Conflict_module of string * string * string
| No_implementation of string
| Not_consistent of string

exception Error of error

let error err = raise (Error err)

let package_not_found ~pkg ~json = error (Package_not_found (pkg, json))
let package_not_found ~pkg = error (Package_not_found pkg)

let print (fmt : Format.formatter) (x : error) =
match x with
| Conflict_module (modname, dir1, dir2) ->
Format.fprintf fmt
"@{<error>Error:@} %s found in two directories: (%s, %s)\n\
File names must be unique per project" modname dir1 dir2
| Not_consistent modname ->
Format.fprintf fmt
"@{<error>Error:@} %s has implementation/interface in non-consistent \
syntax(reason/ocaml)"
modname
| No_implementation modname ->
Format.fprintf fmt "@{<error>Error:@} %s does not have implementation file"
modname
| Package_not_found (name, json_opt) ->
let in_json =
match json_opt with
| None -> Ext_string.empty
| Some x -> " in " ^ x
in
| Package_not_found name ->
let name = Bsb_pkg_types.to_string name in
if Ext_string.equal name !Bs_version.package_name then
Format.fprintf fmt
"File \"bsconfig.json\", line 1\n\
@{<error>Error:@} package @{<error>%s@} is not found %s\n\
@{<error>Error:@} package @{<error>%s@} is not found\n\
It's the basic, required package. If you have it installed globally,\n\
Please run `npm link rescript` to make it available" name in_json
Please run `npm link rescript` to make it available" name
else
Format.fprintf fmt
"File \"bsconfig.json\", line 1\n\
@{<error>Error:@} package @{<error>%s@} not found or built %s\n\
- Did you install it?" name in_json
@{<error>Error:@} package @{<error>%s@} not found or built\n\
- Did you install it?" name
| Json_config (pos, s) ->
Format.fprintf fmt
"File %S, line %d:\n\
Expand All @@ -78,17 +66,12 @@ let print (fmt : Format.formatter) (x : error) =
pos.pos_fname pos.pos_lnum s
| Invalid_spec s ->
Format.fprintf fmt "@{<error>Error: Invalid bsconfig.json %s@}" s
| Invalid_json s ->
Format.fprintf fmt "File %S, line 1\n@{<error>Error: Invalid json format@}"
s

let conflict_module modname dir1 dir2 =
Error (Conflict_module (modname, dir1, dir2))

let no_implementation modname = error (No_implementation modname)

let not_consistent modname = error (Not_consistent modname)

let errorf ~loc fmt =
Format.ksprintf (fun s -> error (Json_config (loc, s))) fmt

Expand All @@ -99,8 +82,6 @@ let config_error config fmt =

let invalid_spec s = error (Invalid_spec s)

let invalid_json s = error (Invalid_json s)

let () =
Printexc.register_printer (fun x ->
match x with
Expand Down
6 changes: 1 addition & 5 deletions compiler/bsb/bsb_exception.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exception Error of error

val print : Format.formatter -> error -> unit

val package_not_found : pkg:Bsb_pkg_types.t -> json:string option -> 'a
val package_not_found : pkg:Bsb_pkg_types.t -> 'a

val conflict_module : string -> string -> string -> exn

Expand All @@ -41,8 +41,4 @@ val config_error : Ext_json_types.t -> string -> 'a

val invalid_spec : string -> 'a

val invalid_json : string -> 'a

val no_implementation : string -> 'a

val not_consistent : string -> 'a
34 changes: 1 addition & 33 deletions compiler/bsb/bsb_pkg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let resolve_bs_package_aux ~cwd (pkg : t) =
check_dir (dir // Bsb_pkg_types.to_string pkg))
with
| Some resolved_dir -> resolved_dir
| None -> Bsb_exception.package_not_found ~pkg ~json:None
| None -> Bsb_exception.package_not_found ~pkg
in
aux cwd

Expand Down Expand Up @@ -97,35 +97,3 @@ let resolve_bs_package ~cwd (package : t) =
"@{<warning>Duplicated package:@} %a %s (chosen) vs %s in %s @."
Bsb_pkg_types.print package x result cwd;
x

(** The package does not need to be a bspackage
example:
{[
resolve_npm_package_file ~cwd "reason/refmt";;
resolve_npm_package_file ~cwd "reason/refmt/xx/yy"
]}
It also returns the path name
Note the input [sub_path] is already converted to physical meaning path according to OS
*)
(* let resolve_npm_package_file ~cwd sub_path = *)
(* let rec aux cwd = *)
(* let abs_marker = cwd // Literals.node_modules // sub_path in *)
(* if Sys.file_exists abs_marker then Some abs_marker *)
(* else *)
(* let cwd' = Filename.dirname cwd in *)
(* if String.length cwd' < String.length cwd then *)
(* aux cwd' *)
(* else *)
(* try *)
(* let abs_marker = *)
(* Sys.getenv "npm_config_prefix" *)
(* // "lib" // Literals.node_modules // sub_path in *)
(* if Sys.file_exists abs_marker *)
(* then Some abs_marker *)
(* else None *)
(* (\* Bs_exception.error (Bs_package_not_found name) *\) *)
(* with *)
(* Not_found -> None *)
(* (\* Bs_exception.error (Bs_package_not_found name) *\) *)
(* in *)
(* aux cwd *)
2 changes: 1 addition & 1 deletion tests/build_tests/weird_deps/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (out.stdout !== "") {
normalizeNewlines(out.stderr),
[
'File "bsconfig.json", line 1',
"Error: package weird not found or built ",
"Error: package weird not found or built",
"- Did you install it?",
"",
].join("\n"),
Expand Down
2 changes: 1 addition & 1 deletion tests/build_tests/weird_devdeps/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (out.stdout !== "") {
out.stderr,
[
'File "bsconfig.json", line 1',
"Error: package weird not found or built ",
"Error: package weird not found or built",
"- Did you install it?",
"",
].join(os.EOL),
Expand Down

0 comments on commit 54c5459

Please sign in to comment.