Adding trait to library causing error in projects dependent on library

I’ve recently added a trait “ConfigurationSupport” to the server framework package Hummingbird. This trait is also setup to be a default trait. I am now finding that for projects dependent on Hummingbird, the first time they update to the latest version of the package they get the following error

error: Traits [ConfigurationSupport] have been enabled on package 'hummingbird' (hummingbird) that declares no traits.

It appears it correctly ascertains the default traits, but when it tries to enable them it can’t find them.

I don’t know if this relevant, at the same time as adding the trait I also added version specific Package.swift files. The trait enabled code on the new swift-configuration package that requires swift 6.2 and the 6.0 and 6.1 Package.swift files don’t include it.

I don’t know if the error is caused by something I’ve done, or if it is an issue in SwiftPM. I’ve tried to narrow this down but can’t replicate with a simpler example.

You can replicate it using the following

swift clone https://github.com/herzi/hummingbird-update-failure
cd hummingbird-update-failure
swift package resolve
swift package update
2 Likes

Thank you for posting the repro steps! This is really helpful. :slight_smile:

I believe I’ve encountered a similar error with this kind of setup before, and the TLDR here is that SwiftPM is computing the graph of enabled traits before it considers whether there’s an available update to a package. This means that it will preemptively fail depending on whether there’s an update involving traits for the packages in the graph.

It sounds like this is the same sort of issue, which means that this is definitely a SwiftPM bug. I will look into this!

3 Likes

Thanks for looking into this. What I found quite strange in that scenario is swift-pm leaving behind a perfectly updated Package.resolved (hummingbird 2.17.0 replaced with 2.18.1); so even if it behaves as expected I wouldn’t expect an update to that file when the exit code is not 0.