Skip to content

Commit

Permalink
Check if directory is mono project (#66)
Browse files Browse the repository at this point in the history
I ran into a bad error message when accidentally running Mono in a
directory that isn't a Mono project. Improve the error message for every
CLI command, except the `mono init` one, because that initializes Mono
in an empty project.
  • Loading branch information
tombruijn authored Jan 18, 2024
1 parent ad5a451 commit 6596f02
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changesets/check-if-mono-project.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "fix"
---

Check if the directory in which Mono is run is Mono project before performing commands. Previously Mono would error with a non-user friendly Ruby error about a missing file. This case is now handled with a better error message.
7 changes: 6 additions & 1 deletion lib/mono/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ class Base

def initialize(options = {})
@options = options
@config = Config.new(YAML.safe_load(File.read("mono.yml")))
config_file = "mono.yml"
unless File.exist?(config_file)
exit_cli "No Mono `#{config_file}` config file found in this " \
"directory!"
end
@config = Config.new(YAML.safe_load(File.read(config_file)))
@language = Language.for(config.language).new(config)
find_packages
validate(options)
Expand Down
10 changes: 4 additions & 6 deletions spec/lib/mono/cli/global_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,16 @@
end
end

context "with unknown error" do
it "prints error and exits" do
context "with no Mono project in directory" do
it "prints error about missing config file and exits" do
prepare_project :empty
output =
capture_stdout do
expect do
in_project { run(["run", "false"]) }
end.to raise_error(SystemCallError)
in_project { run(["run", "false"]) }
end

expect(output).to include(
"An unexpected error was encountered during the `mono run` command. Stopping operation."
"Mono::Error: No Mono `mono.yml` config file found in this directory!"
)
expect(performed_commands).to eql([])
end
Expand Down

0 comments on commit 6596f02

Please sign in to comment.