Skip to content

Commit

Permalink
a better error message for corrupted todo files (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
perryqh authored Apr 12, 2024
1 parent f1a8a2b commit f3d697f
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/packs/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl Pack {
.context("Could not read the package_todo.yml file")?;
serde_yaml::from_str(&package_todo_contents).with_context(|| {
format!(
"Failed to deserialize the package_todo.yml file at {}",
"Failed to deserialize the package_todo.yml file at {}. Try deleting the file and running the `update` command to regenerate it.",
absolute_path_to_package_todo.display()
)
})?
Expand Down
19 changes: 19 additions & 0 deletions tests/corrupt_todo_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use assert_cmd::Command;
use predicates::prelude::*;
mod common;

#[test]
fn test_check_with_corrupt_todo() -> anyhow::Result<()> {
Command::cargo_bin("packs")?
.arg("--project-root")
.arg("tests/fixtures/contains_corrupt_todo")
.arg("--debug")
.arg("check")
.assert()
.failure()
.stderr(predicate::str::contains("Failed to deserialize the package_todo.yml"))
.stderr(predicate::str::contains("Try deleting the file and running the `update` command to regenerate it"));

common::teardown();
Ok(())
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Bar
end
1 change: 1 addition & 0 deletions tests/fixtures/contains_corrupt_todo/packs/bar/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enforce_privacy: true
16 changes: 16 additions & 0 deletions tests/fixtures/contains_corrupt_todo/packs/bar/package_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file contains a list of dependencies that are not part of the long term plan for the
# 'packs/foo' package.
# We should generally work to reduce this list over time.
#
# You can regenerate this file using the following command:
#
# bin/packwerk update-todo
---
packs/foo:
"::Foo":
violations:
- dependency
- privacy
files:
- packs/bar/app/services/bar.rb

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Foo
def calls_bar_with_stated_dependency
Bar
end
end
3 changes: 3 additions & 0 deletions tests/fixtures/contains_corrupt_todo/packs/foo/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enforce_dependencies: true
dependencies:
- packs/bar
11 changes: 11 additions & 0 deletions tests/fixtures/contains_corrupt_todo/packs/foo/package_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file contains a list of dependencies that are not part of the long term plan for the
# 'packs/foo' package.
# We should generally work to reduce this list over time.
#
# You can regenerate this file using the following command:
#
# bin/packwerk update-todo
---
packs/bar:
"::Bar"
- packs/foo/app/services/foo.rb
23 changes: 23 additions & 0 deletions tests/fixtures/contains_corrupt_todo/packwerk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See: Setting up the configuration file
# https://github.com/Shopify/packwerk/blob/main/USAGE.md#setting-up-the-configuration-file

# List of patterns for folder paths to include
# include:
# - "**/*.{rb,rake,erb}"

# List of patterns for folder paths to exclude
# exclude:
# - "{bin,node_modules,script,tmp,vendor}/**/*"

# Patterns to find package configuration files
# package_paths: "**/"

# List of custom associations, if any
# custom_associations:
# - "cache_belongs_to"

# Whether or not you want the cache enabled (disabled by default)
cache: false

# Where you want the cache to be stored (default below)
# cache_directory: 'tmp/cache/packwerk'

0 comments on commit f3d697f

Please sign in to comment.