Skip to content

Commit 51f6656

Browse files
committed
Provide the OID whose lookup failed in the error
1 parent 05067f7 commit 51f6656

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

ObjectiveGit/Categories/NSError+Git.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929

3030
#import <Foundation/Foundation.h>
3131

32+
/// The error domain used by Objective-Git
3233
extern NSString * const GTGitErrorDomain;
3334

35+
/// Error userinfo keys
36+
extern NSString * const GTGitErrorOID;
37+
3438
@interface NSError (Git)
3539

3640
/// Describes the given libgit2 error code, using any message provided by

ObjectiveGit/Categories/NSError+Git.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#import "git2/errors.h"
3232

3333
NSString * const GTGitErrorDomain = @"GTGitErrorDomain";
34+
NSString * const GTGitErrorOID = @"GTOID";
3435

3536
@implementation NSError (Git)
3637

ObjectiveGit/GTRepository.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,10 @@ - (id)lookUpObjectByGitOid:(const git_oid *)oid objectType:(GTObjectType)type er
290290
if (error != NULL) {
291291
char oid_str[GIT_OID_HEXSZ+1];
292292
git_oid_tostr(oid_str, sizeof(oid_str), oid);
293-
*error = [NSError git_errorFor:gitError description:@"Failed to lookup object %s in repository.", oid_str];
293+
*error = [NSError git_errorFor:gitError
294+
description:@"Failed to lookup object"
295+
userInfo:@{GTGitErrorOID: [GTOID oidWithGitOid:oid]}
296+
failureReason:@"The object %s couldn't be found in the repository.", oid_str];
294297
}
295298
return nil;
296299
}

0 commit comments

Comments
 (0)