From: Stefan Sperling Subject: show expected object type in error messages To: gameoftrees@openbsd.org Date: Sat, 9 Oct 2021 13:10:30 +0200 If we fail to find an object which was requested on the command line we should include information about the object's expected type in the error message. For example, given a tree object such as this one: 0fa598530b08cbc69461d14bc790a9c36867d2cb util/ We can view this object with 'got cat' just fine: $ got cat 0fa598 18b329e07759c0334289c970a59481db7e56cc08 0100755 got-build-regress.sh 01e5a1d9194487f5520140ba26cb17db4944406d 0100755 uncompress-loose-object.sh Yet 'got log -c' claims this object did not exist at all: $ got log -c 0fa598 -l1 got: 0fa598: object not found With the patch below, we add a hint about the expected object type. The error message now makes more sense: $ got log -c 0fa598 -l1 got: commit 0fa598: object not found ok? diff ec496083766cab732bffbaf8f134c7905c2ad25b 809cab264e777f08a57d976f83ced5d7c8e5d347 blob - b06c9dd2e1937dcf6624689b565d28b3a51d1c4a blob + 17697cc62656dd554d17df6ee00a548fde19f6e9 --- lib/repository.c +++ lib/repository.c @@ -1485,8 +1485,29 @@ done: if (err) { free(*id); *id = NULL; - } else if (*id == NULL) - err = got_error_path(id_str_prefix, GOT_ERR_NO_OBJ); + } else if (*id == NULL) { + switch (obj_type) { + case GOT_OBJ_TYPE_BLOB: + err = got_error_fmt(GOT_ERR_NO_OBJ, "%s %s", + GOT_OBJ_LABEL_BLOB, id_str_prefix); + break; + case GOT_OBJ_TYPE_TREE: + err = got_error_fmt(GOT_ERR_NO_OBJ, "%s %s", + GOT_OBJ_LABEL_TREE, id_str_prefix); + break; + case GOT_OBJ_TYPE_COMMIT: + err = got_error_fmt(GOT_ERR_NO_OBJ, "%s %s", + GOT_OBJ_LABEL_COMMIT, id_str_prefix); + break; + case GOT_OBJ_TYPE_TAG: + err = got_error_fmt(GOT_ERR_NO_OBJ, "%s %s", + GOT_OBJ_LABEL_TAG, id_str_prefix); + break; + default: + err = got_error_path(id_str_prefix, GOT_ERR_NO_OBJ); + break; + } + } return err; } @@ -1590,7 +1611,8 @@ got_repo_object_match_tag(struct got_tag_object **tag, } if (err == NULL && *tag == NULL) - err = got_error_path(name, GOT_ERR_NO_OBJ); + err = got_error_fmt(GOT_ERR_NO_OBJ, "%s %s", + GOT_OBJ_LABEL_TAG, name); return err; } blob - f4f0029ca41073b2b76c6a560ab229e160f04d55 blob + fb11f286780b130bb30e7694ace57e52e5548050 --- regress/cmdline/log.sh +++ regress/cmdline/log.sh @@ -500,7 +500,8 @@ test_log_end_at_commit() { return 1 fi echo -n > $testroot/stdout.expected - echo "got: $empty_sha1: object not found" > $testroot/stderr.expected + echo "got: commit $empty_sha1: object not found" \ + > $testroot/stderr.expected cmp -s $testroot/stderr.expected $testroot/stderr ret="$?" if [ "$ret" != "0" ]; then blob - fdc7ff875ee50b4012f757c1df86b00c41cd3dd0 blob + 6e76b311f1077b2317955711690448d4be3efebc --- regress/cmdline/tag.sh +++ regress/cmdline/tag.sh @@ -98,7 +98,8 @@ test_tag_create() { return 1 fi - echo "got: $tree_id: object not found" > $testroot/stderr.expected + echo "got: commit $tree_id: object not found" \ + > $testroot/stderr.expected cmp -s $testroot/stderr $testroot/stderr.expected ret="$?" if [ "$ret" != "0" ]; then