Skip to content

Commit 33e94fe

Browse files
committed
libstore: Make AwsAuthError more legible
Instead of the cryptic: > error: Failed to resolve AWS credentials: error code 6153` We now get more legible: > error: AWS authentication error: 'Valid credentials could not be sourced by the IMDS provider' (6153)
1 parent dc03c6a commit 33e94fe

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/libstore/aws-creds.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
namespace nix {
2424

25+
AwsAuthError::AwsAuthError(int errorCode)
26+
: Error("AWS authentication error: '%s' (%d)", aws_error_str(errorCode), errorCode)
27+
, errorCode(errorCode)
28+
{
29+
}
30+
2531
namespace {
2632

2733
static AwsCredentials getCredentialsFromProvider(std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider> provider)
@@ -35,8 +41,7 @@ static AwsCredentials getCredentialsFromProvider(std::shared_ptr<Aws::Crt::Auth:
3541

3642
provider->GetCredentials([prom](std::shared_ptr<Aws::Crt::Auth::Credentials> credentials, int errorCode) {
3743
if (errorCode != 0 || !credentials) {
38-
prom->set_exception(
39-
std::make_exception_ptr(AwsAuthError("Failed to resolve AWS credentials: error code %d", errorCode)));
44+
prom->set_exception(std::make_exception_ptr(AwsAuthError(errorCode)));
4045
} else {
4146
auto accessKeyId = Aws::Crt::ByteCursorToStringView(credentials->GetAccessKeyId());
4247
auto secretAccessKey = Aws::Crt::ByteCursorToStringView(credentials->GetSecretAccessKey());

src/libstore/include/nix/store/aws-creds.hh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,19 @@ struct AwsCredentials
3434
}
3535
};
3636

37-
/**
38-
* Exception thrown when AWS authentication fails
39-
*/
40-
MakeError(AwsAuthError, Error);
37+
class AwsAuthError : public Error
38+
{
39+
std::optional<int> errorCode;
40+
41+
public:
42+
using Error::Error;
43+
AwsAuthError(int errorCode);
44+
45+
std::optional<int> getErrorCode() const
46+
{
47+
return errorCode;
48+
}
49+
};
4150

4251
class AwsCredentialProvider
4352
{

src/libstore/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ curl_s3_store_opt = get_option('curl-s3-store').require(
158158

159159
if curl_s3_store_opt.enabled()
160160
deps_other += aws_crt_cpp
161+
aws_c_common = cxx.find_library('aws-c-common', required : true)
162+
deps_other += aws_c_common
161163
endif
162164

163165
configdata_pub.set('NIX_WITH_AWS_AUTH', curl_s3_store_opt.enabled().to_int())

0 commit comments

Comments
 (0)