Skip to content

Commit

Permalink
feat: Include name of target in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Apr 22, 2024
1 parent 89fab4b commit 4a9d0e4
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
11 changes: 7 additions & 4 deletions internal/cmd/config.go
Expand Up @@ -652,11 +652,14 @@ func (c *Config) applyArgs(
switch err := sourceState.Apply(targetSystem, c.destSystem, c.persistentState, targetDirAbsPath, targetRelPath, applyOptions); {
case errors.Is(err, fs.SkipDir):
continue
case err != nil && c.keepGoing:
c.errorf("%v\n", err)
keptGoingAfterErr = true
case err != nil:
return err
err = fmt.Errorf("%s: %w", targetRelPath, err)
if c.keepGoing {
c.errorf("%v\n", err)
keptGoingAfterErr = true
} else {
return err
}
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/cmd/testdata/scripts/apply.txtar
Expand Up @@ -69,3 +69,4 @@ grep -count=2 '# edited' $HOME/.file

# test that chezmoi apply --source-path fails when called with a targetDirAbsPath
! exec chezmoi apply --force --source-path $HOME${/}.file
[!windows] stderr ${HOME@R}/\.file:\snot\sin\s${CHEZMOISOURCEDIR@R}$
2 changes: 1 addition & 1 deletion internal/cmd/testdata/scripts/external.txtar
Expand Up @@ -97,7 +97,7 @@ chhome home11/user

# test that checksums detect corrupt files
! exec chezmoi apply --force
stderr 'MD5 mismatch'
stderr \.file:\sMD5\smismatch
stderr 'SHA256 mismatch'

chhome home12/user
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/testdata/scripts/keepgoing.txtar
Expand Up @@ -8,6 +8,7 @@ mkhomedir
cmp $HOME/1ok golden/1ok
! exists $HOME/2error
! exists $HOME/3ok
stderr '2error: template: 2error\.tmpl:2: unclosed action started at 2error\.tmpl:1'

# test that chezmoi apply with --keep-going writes all files that it can without errors
! exec chezmoi apply --force --keep-going
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/testdata/scripts/noencryption.txtar
Expand Up @@ -6,7 +6,7 @@ stderr 'no encryption'

# test that chezmoi apply without encryption fails
! exec chezmoi apply --force
stderr 'no encryption'
stderr \.encrypted:\sno\sencryption$

-- home/user/.encrypted --
# contents of .encrypted
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/testdata/scripts/scriptsdir_unix.txtar
Expand Up @@ -8,13 +8,13 @@ chhome home2/user

# test that chezmoi apply fails if .chezmoiscripts contains a non-script
! exec chezmoi apply
stderr 'not a script'
stderr ${CHEZMOISOURCEDIR@R}/\.chezmoiscripts/dot_file:\snot\sa\sscript$

chhome home3/user

# test that chezmoi apply fails if .chezmoiscripts contains duplicate targets
! exec chezmoi apply
stderr 'inconsistent state'
stderr \.chezmoiscripts/script\.sh:\sinconsistent\sstate

chhome home4/user

Expand Down

0 comments on commit 4a9d0e4

Please sign in to comment.