Skip to content

Commit 54c5459

Browse files
authored
Remove unused stuff from Bsb_exception (#7130)
* Remove unused bsb exception types * Bsb_exception.Package_not_found: removed unused param
1 parent 60b99ea commit 54c5459

File tree

5 files changed

+11
-66
lines changed

5 files changed

+11
-66
lines changed

compiler/bsb/bsb_exception.ml

+7-26
Original file line numberDiff line numberDiff line change
@@ -23,52 +23,40 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525
type error =
26-
| Package_not_found of Bsb_pkg_types.t * string option (* json file *)
26+
| Package_not_found of Bsb_pkg_types.t
2727
| Json_config of Ext_position.t * string
28-
| Invalid_json of string
2928
| Invalid_spec of string
3029
| Conflict_module of string * string * string
3130
| No_implementation of string
32-
| Not_consistent of string
3331

3432
exception Error of error
3533

3634
let error err = raise (Error err)
3735

38-
let package_not_found ~pkg ~json = error (Package_not_found (pkg, json))
36+
let package_not_found ~pkg = error (Package_not_found pkg)
3937

4038
let print (fmt : Format.formatter) (x : error) =
4139
match x with
4240
| Conflict_module (modname, dir1, dir2) ->
4341
Format.fprintf fmt
4442
"@{<error>Error:@} %s found in two directories: (%s, %s)\n\
4543
File names must be unique per project" modname dir1 dir2
46-
| Not_consistent modname ->
47-
Format.fprintf fmt
48-
"@{<error>Error:@} %s has implementation/interface in non-consistent \
49-
syntax(reason/ocaml)"
50-
modname
5144
| No_implementation modname ->
5245
Format.fprintf fmt "@{<error>Error:@} %s does not have implementation file"
5346
modname
54-
| Package_not_found (name, json_opt) ->
55-
let in_json =
56-
match json_opt with
57-
| None -> Ext_string.empty
58-
| Some x -> " in " ^ x
59-
in
47+
| Package_not_found name ->
6048
let name = Bsb_pkg_types.to_string name in
6149
if Ext_string.equal name !Bs_version.package_name then
6250
Format.fprintf fmt
6351
"File \"bsconfig.json\", line 1\n\
64-
@{<error>Error:@} package @{<error>%s@} is not found %s\n\
52+
@{<error>Error:@} package @{<error>%s@} is not found\n\
6553
It's the basic, required package. If you have it installed globally,\n\
66-
Please run `npm link rescript` to make it available" name in_json
54+
Please run `npm link rescript` to make it available" name
6755
else
6856
Format.fprintf fmt
6957
"File \"bsconfig.json\", line 1\n\
70-
@{<error>Error:@} package @{<error>%s@} not found or built %s\n\
71-
- Did you install it?" name in_json
58+
@{<error>Error:@} package @{<error>%s@} not found or built\n\
59+
- Did you install it?" name
7260
| Json_config (pos, s) ->
7361
Format.fprintf fmt
7462
"File %S, line %d:\n\
@@ -78,17 +66,12 @@ let print (fmt : Format.formatter) (x : error) =
7866
pos.pos_fname pos.pos_lnum s
7967
| Invalid_spec s ->
8068
Format.fprintf fmt "@{<error>Error: Invalid bsconfig.json %s@}" s
81-
| Invalid_json s ->
82-
Format.fprintf fmt "File %S, line 1\n@{<error>Error: Invalid json format@}"
83-
s
8469

8570
let conflict_module modname dir1 dir2 =
8671
Error (Conflict_module (modname, dir1, dir2))
8772

8873
let no_implementation modname = error (No_implementation modname)
8974

90-
let not_consistent modname = error (Not_consistent modname)
91-
9275
let errorf ~loc fmt =
9376
Format.ksprintf (fun s -> error (Json_config (loc, s))) fmt
9477

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

10083
let invalid_spec s = error (Invalid_spec s)
10184

102-
let invalid_json s = error (Invalid_json s)
103-
10485
let () =
10586
Printexc.register_printer (fun x ->
10687
match x with

compiler/bsb/bsb_exception.mli

+1-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ exception Error of error
3131

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

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

3636
val conflict_module : string -> string -> string -> exn
3737

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

4242
val invalid_spec : string -> 'a
4343

44-
val invalid_json : string -> 'a
45-
4644
val no_implementation : string -> 'a
47-
48-
val not_consistent : string -> 'a

compiler/bsb/bsb_pkg.ml

+1-33
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ let resolve_bs_package_aux ~cwd (pkg : t) =
6565
check_dir (dir // Bsb_pkg_types.to_string pkg))
6666
with
6767
| Some resolved_dir -> resolved_dir
68-
| None -> Bsb_exception.package_not_found ~pkg ~json:None
68+
| None -> Bsb_exception.package_not_found ~pkg
6969
in
7070
aux cwd
7171

@@ -97,35 +97,3 @@ let resolve_bs_package ~cwd (package : t) =
9797
"@{<warning>Duplicated package:@} %a %s (chosen) vs %s in %s @."
9898
Bsb_pkg_types.print package x result cwd;
9999
x
100-
101-
(** The package does not need to be a bspackage
102-
example:
103-
{[
104-
resolve_npm_package_file ~cwd "reason/refmt";;
105-
resolve_npm_package_file ~cwd "reason/refmt/xx/yy"
106-
]}
107-
It also returns the path name
108-
Note the input [sub_path] is already converted to physical meaning path according to OS
109-
*)
110-
(* let resolve_npm_package_file ~cwd sub_path = *)
111-
(* let rec aux cwd = *)
112-
(* let abs_marker = cwd // Literals.node_modules // sub_path in *)
113-
(* if Sys.file_exists abs_marker then Some abs_marker *)
114-
(* else *)
115-
(* let cwd' = Filename.dirname cwd in *)
116-
(* if String.length cwd' < String.length cwd then *)
117-
(* aux cwd' *)
118-
(* else *)
119-
(* try *)
120-
(* let abs_marker = *)
121-
(* Sys.getenv "npm_config_prefix" *)
122-
(* // "lib" // Literals.node_modules // sub_path in *)
123-
(* if Sys.file_exists abs_marker *)
124-
(* then Some abs_marker *)
125-
(* else None *)
126-
(* (\* Bs_exception.error (Bs_package_not_found name) *\) *)
127-
(* with *)
128-
(* Not_found -> None *)
129-
(* (\* Bs_exception.error (Bs_package_not_found name) *\) *)
130-
(* in *)
131-
(* aux cwd *)

tests/build_tests/weird_deps/input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (out.stdout !== "") {
1717
normalizeNewlines(out.stderr),
1818
[
1919
'File "bsconfig.json", line 1',
20-
"Error: package weird not found or built ",
20+
"Error: package weird not found or built",
2121
"- Did you install it?",
2222
"",
2323
].join("\n"),

tests/build_tests/weird_devdeps/input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (out.stdout !== "") {
1717
out.stderr,
1818
[
1919
'File "bsconfig.json", line 1',
20-
"Error: package weird not found or built ",
20+
"Error: package weird not found or built",
2121
"- Did you install it?",
2222
"",
2323
].join(os.EOL),

0 commit comments

Comments
 (0)