fix: preserve preparation errors when formatting conflicts
@@ -9,6 +9,26 @@ import os
99import testdb
1010import time
1111
12+fn test_prepare_conflict_keeps_its_error_kind_after_copying_names() ! {
13+ s := fake_system('prepare_conflict_kind')!
14+ defer { os.rmdir_all(s.tmp) or { went_on('remove the test system', err) } }
15+ testdb.write_local(s.path('db'), [testdb.Pkg{ name: 'old', conflicts: ['new'] }])!
16+ s.publish([FakePkg{ name: 'new' }])!
17+ handle := alpm.initialize(s.path('root'), s.path('db'))!
18+ defer { handle.release() or { went_on('release the alpm handle', err) } }
19+ db := handle.register_syncdb('core', 0)!
20+ trans_begin(handle, .nolock)!
21+ defer { trans_cleanup(handle) }
22+ handle.add_pkg(db.get_pkg('new') or { return error('missing new package') })!
23+ trans_prepare_checked(handle) or {
24+ assert err.code() == int(alpm.Errno.conflicting_deps)
25+ assert err.msg().contains('unresolvable package conflicts:')
26+ assert err.msg().contains('new and old are in conflict')
27+ return
28+ }
29+ assert false, 'the conflicting transaction was accepted'
30+}
31+
1232#include <stdio_ext.h>
1333
1434fn C.__fpurge(stream &C.FILE)
@@ -201,8 +201,9 @@ fn trans_prepare_checked(handle &alpm.Handle) ! {
201201 if problems.len == 0 {
202202 return err
203203 }
204- // the errno is still the prepare's: nothing called libalpm since
205- return error(prepare_problem_lines(handle.errno(), problems).join('\n'))
204+ // copying conflict package names can reset the handle's mutable errno.
205+ kind := unsafe { alpm.Errno(err.code()) }
206+ return error_with_code(prepare_problem_lines(kind, problems).join('\n'), err.code())
206207 }
207208}
208209