Commit Diff


commit - 7fbaa4f345d7c34db7ec62930b1d01fc3fbf0b32
commit + 230a42bdc60c6136d2a5ce65bf1a2f26d990c096
blob - d07adf06cf9ef57d268916fd7e1b64d6e19d09ff
blob + 6498094b62b98fd7a10f6879d38b0f0c06c80f99
--- got/got.c
+++ got/got.c
@@ -206,20 +206,20 @@ apply_unveil(const char *repo_path, int repo_read_only
 	}
 
 	if (repo_path && unveil(repo_path, repo_read_only ? "r" : "rwc") != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("unveil", repo_path);
 
 	if (worktree_path && unveil(worktree_path, "rwc") != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("unveil", worktree_path);
 
 	if (unveil("/tmp", "rwc") != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("unveil", "/tmp");
 
 	error = got_privsep_unveil_exec_helpers();
 	if (error != NULL)
 		return error;
 
 	if (unveil(NULL, NULL) != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("unveil");
 
 	return NULL;
 }
@@ -329,7 +329,7 @@ cmd_checkout(int argc, char *argv[])
 		case 'c':
 			commit_id_str = strdup(optarg);
 			if (commit_id_str == NULL)
-				return got_error_from_errno();
+				return got_error_prefix_errno("strdup");
 			break;
 		case 'p':
 			path_prefix = optarg;
@@ -352,25 +352,32 @@ cmd_checkout(int argc, char *argv[])
 		char *cwd, *base, *dotgit;
 		repo_path = realpath(argv[0], NULL);
 		if (repo_path == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno2("realpath", argv[0]);
 		cwd = getcwd(NULL, 0);
 		if (cwd == NULL) {
-			error = got_error_from_errno();
+			error = got_error_prefix_errno("getcwd");
 			goto done;
 		}
-		if (path_prefix[0])
-			base = basename(path_prefix);
-		else
+		if (path_prefix[0]) {
+			base = basename(path_prefix);
+			if (base == NULL) {
+				error = got_error_prefix_errno2("basename",
+				    path_prefix);
+				goto done;
+			}
+		} else {
 			base = basename(repo_path);
-		if (base == NULL) {
-			error = got_error_from_errno();
-			goto done;
+			if (base == NULL) {
+				error = got_error_prefix_errno2("basename",
+				    repo_path);
+				goto done;
+			}
 		}
 		dotgit = strstr(base, ".git");
 		if (dotgit)
 			*dotgit = '\0';
 		if (asprintf(&worktree_path, "%s/%s", cwd, base) == -1) {
-			error = got_error_from_errno();
+			error = got_error_prefix_errno("asprintf");
 			free(cwd);
 			goto done;
 		}
@@ -378,12 +385,12 @@ cmd_checkout(int argc, char *argv[])
 	} else if (argc == 2) {
 		repo_path = realpath(argv[0], NULL);
 		if (repo_path == NULL) {
-			error = got_error_from_errno();
+			error = got_error_prefix_errno2("realpath", argv[0]);
 			goto done;
 		}
 		worktree_path = realpath(argv[1], NULL);
 		if (worktree_path == NULL) {
-			error = got_error_from_errno();
+			error = got_error_prefix_errno2("realpath", argv[1]);
 			goto done;
 		}
 	} else
@@ -491,7 +498,7 @@ cmd_update(int argc, char *argv[])
 		case 'c':
 			commit_id_str = strdup(optarg);
 			if (commit_id_str == NULL)
-				return got_error_from_errno();
+				return got_error_prefix_errno("strdup");
 			break;
 		default:
 			usage_update();
@@ -509,7 +516,7 @@ cmd_update(int argc, char *argv[])
 #endif
 	worktree_path = getcwd(NULL, 0);
 	if (worktree_path == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("getcwd");
 		goto done;
 	}
 	error = got_worktree_open(&worktree, worktree_path);
@@ -519,7 +526,7 @@ cmd_update(int argc, char *argv[])
 	if (argc == 0) {
 		path = strdup("");
 		if (path == NULL) {
-			error = got_error_from_errno();
+			error = got_error_prefix_errno("strdup");
 			goto done;
 		}
 	} else if (argc == 1) {
@@ -675,7 +682,7 @@ print_commit(struct got_commit_object *commit, struct 
 		s = refs_str;
 		if (asprintf(&refs_str, "%s%s%s", s ? s : "", s ? ", " : "",
 		    name) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("asprintf");
 			free(s);
 			break;
 		}
@@ -716,7 +723,7 @@ print_commit(struct got_commit_object *commit, struct 
 
 	logmsg0 = strdup(got_object_commit_get_logmsg(commit));
 	if (logmsg0 == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("strdup");
 
 	logmsg = logmsg0;
 	do {
@@ -733,7 +740,7 @@ print_commit(struct got_commit_object *commit, struct 
 	}
 
 	if (fflush(stdout) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fflush");
 	return err;
 }
 
@@ -861,7 +868,7 @@ cmd_log(int argc, char *argv[])
 
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("getcwd");
 		goto done;
 	}
 
@@ -873,7 +880,7 @@ cmd_log(int argc, char *argv[])
 	if (argc == 0) {
 		path = strdup("");
 		if (path == NULL) {
-			error = got_error_from_errno();
+			error = got_error_prefix_errno("strdup");
 			goto done;
 		}
 	} else if (argc == 1) {
@@ -885,7 +892,7 @@ cmd_log(int argc, char *argv[])
 		} else {
 			path = strdup(argv[0]);
 			if (path == NULL) {
-				error = got_error_from_errno();
+				error = got_error_prefix_errno("strdup");
 				goto done;
 			}
 		}
@@ -897,7 +904,7 @@ cmd_log(int argc, char *argv[])
 		    strdup(got_worktree_get_repo_path(worktree)) : strdup(cwd);
 	}
 	if (repo_path == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("strdup");
 		goto done;
 	}
 
@@ -947,7 +954,8 @@ cmd_log(int argc, char *argv[])
 				id = got_object_id_dup(
 				    got_object_tag_get_object_id(tag));
 				if (id == NULL)
-					error = got_error_from_errno();
+					error = got_error_prefix_errno(
+					    "got_object_id_dup");
 				got_object_tag_close(tag);
 				if (error)
 					goto done;
@@ -1047,17 +1055,17 @@ print_diff(void *arg, unsigned char status, const char
 	if (status != GOT_STATUS_DELETE) {
 		if (asprintf(&abspath, "%s/%s",
 		    got_worktree_get_root_path(a->worktree), path) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("asprintf");
 			goto done;
 		}
 
 		f2 = fopen(abspath, "r");
 		if (f2 == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("fopen", abspath);
 			goto done;
 		}
 		if (lstat(abspath, &sb) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("lstat", abspath);
 			goto done;
 		}
 	} else
@@ -1069,7 +1077,7 @@ done:
 	if (blob1)
 		got_object_blob_close(blob1);
 	if (f2 && fclose(f2) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	free(abspath);
 	return err;
 }
@@ -1118,7 +1126,7 @@ cmd_diff(int argc, char *argv[])
 
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("getcwd");
 		goto done;
 	}
 	error = got_worktree_open(&worktree, cwd);
@@ -1134,7 +1142,7 @@ cmd_diff(int argc, char *argv[])
 			    "-r option can't be used when diffing a work tree");
 		repo_path = strdup(got_worktree_get_repo_path(worktree));
 		if (repo_path == NULL) {
-			error = got_error_from_errno();
+			error = got_error_prefix_errno("strdup");
 			goto done;
 		}
 		if (argc == 1) {
@@ -1145,7 +1153,7 @@ cmd_diff(int argc, char *argv[])
 		} else {
 			path = strdup("");
 			if (path == NULL) {
-				error = got_error_from_errno();
+				error = got_error_prefix_errno("strdup");
 				goto done;
 			}
 		}
@@ -1158,7 +1166,7 @@ cmd_diff(int argc, char *argv[])
 	if (repo_path == NULL) {
 		repo_path = getcwd(NULL, 0);
 		if (repo_path == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno("getcwd");
 	}
 
 	error = got_repo_open(&repo, repo_path);
@@ -1298,7 +1306,7 @@ cmd_blame(int argc, char *argv[])
 
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("getcwd");
 		goto done;
 	}
 	if (repo_path == NULL) {
@@ -1311,13 +1319,13 @@ cmd_blame(int argc, char *argv[])
 			repo_path =
 			    strdup(got_worktree_get_repo_path(worktree));
 			if (repo_path == NULL)
-				error = got_error_from_errno();
+				error = got_error_prefix_errno("strdup");
 			if (error)
 				goto done;
 		} else {
 			repo_path = strdup(cwd);
 			if (repo_path == NULL) {
-				error = got_error_from_errno();
+				error = got_error_prefix_errno("strdup");
 				goto done;
 			}
 		}
@@ -1339,7 +1347,7 @@ cmd_blame(int argc, char *argv[])
 		    prefix, (strcmp(prefix, "/") != 0) ? "/" : "",
 		    worktree_subdir, worktree_subdir[0] ? "/" : "",
 		    path) == -1) {
-			error = got_error_from_errno();
+			error = got_error_prefix_errno("asprintf");
 			goto done;
 		}
 		error = got_repo_map_path(&in_repo_path, repo, p, 0);
@@ -1439,7 +1447,7 @@ print_tree(const char *path, struct got_object_id *com
 			if (err)
 				goto done;
 			if (asprintf(&id, "%s ", id_str) == -1) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("asprintf");
 				free(id_str);
 				goto done;
 			}
@@ -1453,7 +1461,7 @@ print_tree(const char *path, struct got_object_id *com
 			if (asprintf(&child_path, "%s%s%s", path,
 			    path[0] == '/' && path[1] == '\0' ? "" : "/",
 			    te->name) == -1) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("asprintf");
 				goto done;
 			}
 			err = print_tree(child_path, commit_id, show_ids, 1,
@@ -1526,7 +1534,7 @@ cmd_tree(int argc, char *argv[])
 
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("getcwd");
 		goto done;
 	}
 	if (repo_path == NULL) {
@@ -1539,13 +1547,13 @@ cmd_tree(int argc, char *argv[])
 			repo_path =
 			    strdup(got_worktree_get_repo_path(worktree));
 			if (repo_path == NULL)
-				error = got_error_from_errno();
+				error = got_error_prefix_errno("strdup");
 			if (error)
 				goto done;
 		} else {
 			repo_path = strdup(cwd);
 			if (repo_path == NULL) {
-				error = got_error_from_errno();
+				error = got_error_prefix_errno("strdup");
 				goto done;
 			}
 		}
@@ -1566,7 +1574,7 @@ cmd_tree(int argc, char *argv[])
 			if (asprintf(&p, "%s/%s",
 			    got_worktree_get_path_prefix(worktree),
 			    worktree_subdir) == -1) {
-				error = got_error_from_errno();
+				error = got_error_prefix_errno("asprintf");
 				goto done;
 			}
 			error = got_repo_map_path(&in_repo_path, repo, p, 1);
@@ -1658,7 +1666,7 @@ cmd_status(int argc, char *argv[])
 #endif
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("getcwd");
 		goto done;
 	}
 
@@ -1669,7 +1677,7 @@ cmd_status(int argc, char *argv[])
 	if (argc == 0) {
 		path = strdup("");
 		if (path == NULL) {
-			error = got_error_from_errno();
+			error = got_error_prefix_errno("strdup");
 			goto done;
 		}
 	} else if (argc == 1) {
@@ -1721,7 +1729,7 @@ list_refs(struct got_repository *repo)
 		char *refstr;
 		refstr = got_ref_to_str(re->ref);
 		if (refstr == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno("got_ref_to_str");
 		printf("%s: %s\n", got_ref_get_name(re->ref), refstr);
 		free(refstr);
 	}
@@ -1824,7 +1832,7 @@ cmd_ref(int argc, char *argv[])
 #endif
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("getcwd");
 		goto done;
 	}
 
@@ -1838,13 +1846,13 @@ cmd_ref(int argc, char *argv[])
 			repo_path =
 			    strdup(got_worktree_get_repo_path(worktree));
 			if (repo_path == NULL)
-				error = got_error_from_errno();
+				error = got_error_prefix_errno("strdup");
 			if (error)
 				goto done;
 		} else {
 			repo_path = strdup(cwd);
 			if (repo_path == NULL) {
-				error = got_error_from_errno();
+				error = got_error_prefix_errno("strdup");
 				goto done;
 			}
 		}
@@ -1907,14 +1915,14 @@ cmd_add(int argc, char *argv[])
 
 	path = realpath(argv[0], NULL);
 	if (path == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno2("realpath", argv[0]);
 		goto done;
 	}
 	got_path_strip_trailing_slashes(path);
 
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("getcwd");
 		goto done;
 	}
 	error = got_worktree_open(&worktree, cwd);
@@ -1980,14 +1988,14 @@ cmd_rm(int argc, char *argv[])
 
 	path = realpath(argv[0], NULL);
 	if (path == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno2("realpath", argv[0]);
 		goto done;
 	}
 	got_path_strip_trailing_slashes(path);
 
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("getcwd");
 		goto done;
 	}
 	error = got_worktree_open(&worktree, cwd);
@@ -2057,14 +2065,14 @@ cmd_revert(int argc, char *argv[])
 
 	path = realpath(argv[0], NULL);
 	if (path == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno2("realpath", argv[0]);
 		goto done;
 	}
 	got_path_strip_trailing_slashes(path);
 
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("getcwd");
 		goto done;
 	}
 	error = got_worktree_open(&worktree, cwd);
@@ -2130,7 +2138,7 @@ cmd_commit(int argc, char *argv[])
 	if (argc == 1) {
 		path = realpath(argv[0], NULL);
 		if (path == NULL) {
-			error = got_error_from_errno();
+			error = got_error_prefix_errno2("realpath", argv[0]);
 			goto done;
 		}
 		got_path_strip_trailing_slashes(path);
@@ -2145,7 +2153,7 @@ cmd_commit(int argc, char *argv[])
 
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("getcwd");
 		goto done;
 	}
 	error = got_worktree_open(&worktree, cwd);
blob - afb23f67b0069ffb34bd9a781d2741d3ee1d5e8c
blob + 3fd5c9691747bbc32bf4cb8757224588b633262a
--- include/got_error.h
+++ include/got_error.h
@@ -185,18 +185,27 @@ const struct got_error *got_error_msg(int, const char 
 
 /*
  * Get a statically allocated error object with code GOT_ERR_ERRNO
- * and an error message obtained from strerror(3).
+ * and an error message obtained from strerror(3), prefixed with a
+ * string.
  */
-const struct got_error *got_error_from_errno(void);
+const struct got_error *got_error_prefix_errno(const char *);
 
 /*
  * Get a statically allocated error object with code GOT_ERR_ERRNO
- * and an error message obtained from strerror(3), prefixed with a
- * string.
+ * and an error message obtained from strerror(3), prefixed with two
+ * strings.
  */
-const struct got_error *got_error_prefix_errno(const char *);
+const struct got_error *got_error_prefix_errno2(const char *, const char *);
 
 /*
+ * Get a statically allocated error object with code GOT_ERR_ERRNO
+ * and an error message obtained from strerror(3), prefixed with three
+ * strings.
+ */
+const struct got_error *got_error_prefix_errno3(const char *, const char *,
+    const char *);
+
+/*
  * Set errno to the specified error code and return a statically
  * allocated error object with code GOT_ERR_ERRNO and an error
  * message obtained from strerror(3).
@@ -205,7 +214,7 @@ const struct got_error *got_error_set_errno(int);
 
 /*
  * If ferror(3) indicates an error status for the FILE, obtain an error
- * from got_error_from_errno(). Else, obtain the error via got_error()
+ * from got_error_prefix_errno(). Else, obtain the error via got_error()
  * with the error code provided in the second argument.
  */
 const struct got_error *got_ferror(FILE *, int);
blob - fab454738ef35e0a79f179d4d18cc12f07be0ec7
blob + 3de5cb388b155a3d5a213e67aa219451b27e74b5
--- lib/blame.c
+++ lib/blame.c
@@ -76,11 +76,11 @@ alloc_diff_offsets(struct got_blame_diff_offsets **dif
 
 	*diff_offsets = calloc(1, sizeof(**diff_offsets));
 	if (*diff_offsets == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	(*diff_offsets)->commit_id = got_object_id_dup(commit_id);
 	if ((*diff_offsets)->commit_id == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_object_id_dup");
 		free_diff_offsets(*diff_offsets);
 		*diff_offsets = NULL;
 		return err;
@@ -275,7 +275,7 @@ blame_close(struct got_blame *blame)
 	struct got_blame_diff_offsets *diff_offsets;
 
 	if (blame->f && fclose(blame->f) != 0)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	free(blame->lines);
 	while (!SLIST_EMPTY(&blame->diff_offsets_list)) {
 		diff_offsets = SLIST_FIRST(&blame->diff_offsets_list);
@@ -322,11 +322,11 @@ blame_open(struct got_blame **blamep, const char *path
 
 	blame = calloc(1, sizeof(*blame));
 	if (blame == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	blame->f = got_opentemp();
 	if (blame->f == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_opentemp");
 		goto done;
 	}
 	err = got_object_blob_dump_to_file(NULL, &blame->nlines, blame->f,
@@ -336,7 +336,7 @@ blame_open(struct got_blame **blamep, const char *path
 
 	blame->lines = calloc(blame->nlines, sizeof(*blame->lines));
 	if (blame->lines == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("calloc");
 		goto done;
 	}
 
@@ -440,7 +440,7 @@ got_blame(const char *path, struct got_object_id *star
 	char *abspath;
 
 	if (asprintf(&abspath, "%s%s", path[0] == '/' ? "" : "/", path) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("asprintf", path);
 
 	err = blame_open(&blame, abspath, start_commit_id, repo, NULL, NULL);
 	if (err) {
@@ -451,7 +451,7 @@ got_blame(const char *path, struct got_object_id *star
 	for (lineno = 1; lineno <= blame->nlines; lineno++) {
 		struct got_object_id *id;
 		char *line, *id_str;
-		
+
 		line = parse_next_line(blame->f, NULL);
 		if (line == NULL)
 			break;
@@ -490,7 +490,7 @@ got_blame_incremental(const char *path, struct got_obj
 	char *abspath;
 
 	if (asprintf(&abspath, "%s%s", path[0] == '/' ? "" : "/", path) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("asprintf", path);
 
 	err = blame_open(&blame, abspath, commit_id, repo, cb, arg);
 	free(abspath);
blob - 6fa9823d42b1356e726625f9d938f1f74ec1b0c9
blob + 6f412d212911276fa303f51f02ccb124f9aa32bf
--- lib/buf.c
+++ lib/buf.c
@@ -297,20 +297,20 @@ buf_write(BUF *b, const char *path, mode_t mode)
 		if (errno == EACCES && unlink(path) != -1)
 			goto open;
 		else
-			return got_error_from_errno();
+			return got_error_prefix_errno2("open", path);
 	}
 
 	if (buf_write_fd(b, fd) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("buf_write_fd");
 		(void)unlink(path);
 		return err;
 	}
 
 	if (fchmod(fd, mode) < 0)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("fchmod", path);
 
 	if (close(fd) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("close", path);
 
 	return err;
 }
@@ -327,17 +327,17 @@ buf_write_stmp(BUF *b, char *template, struct wklhead 
 	int fd;
 
 	if ((fd = mkstemp(template)) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("mkstemp");
 
 	worklist_add(template, temp_files);
 
 	if (buf_write_fd(b, fd) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("buf_write_fd");
 		(void)unlink(template);
 	}
 
 	if (close(fd) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 
 	return err;
 }
@@ -352,7 +352,7 @@ buf_grow(BUF *b, size_t len)
 	u_char *buf;
 	buf = reallocarray(b->cb_buf, 1, b->cb_size + len);
 	if (buf == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("reallocarray");
 	b->cb_buf = buf;
 	b->cb_size += len;
 	return NULL;
blob - ebce7f7027aeb718420ab89f7d105782e677c30d
blob + 24bb6f059b662c9b702545dbebbe7167e4469b6b
--- lib/commit_graph.c
+++ lib/commit_graph.c
@@ -343,7 +343,7 @@ add_node(struct got_commit_graph_node **new_node, int 
 
 	node = calloc(1, sizeof(*node));
 	if (node == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	memcpy(&node->id, commit_id, sizeof(node->id));
 	node->timestamp = commit->committer_time;
@@ -405,7 +405,7 @@ got_commit_graph_open(struct got_commit_graph **graph,
 	*graph = alloc_graph(path);
 	if (*graph == NULL) {
 		got_object_commit_close(commit);
-		return got_error_from_errno();
+		return got_error_prefix_errno("got_object_commit_close");
 	}
 
 	if (first_parent_traversal)
@@ -485,7 +485,7 @@ fetch_commits_from_open_branches(int *nfetched,
 		tips = recallocarray(graph->tips, graph->ntips, ntips,
 		    sizeof(*tips));
 		if (tips == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno("recallocarray");
 		graph->tips = tips;
 		graph->ntips = ntips;
 	}
blob - dc7337a52c9983c9eef7461efc7e58772347d66f
blob + 9132c5f35b58d61b77c0903aae8453c5c904e90e
--- lib/deflate.c
+++ lib/deflate.c
@@ -47,10 +47,10 @@ got_deflate_init(struct got_deflate_buf *zb, uint8_t *
 	zerr = deflateInit(&zb->z, Z_DEFAULT_COMPRESSION);
 	if (zerr != Z_OK) {
 		if  (zerr == Z_ERRNO)
-			return got_error_from_errno();
+			return got_error_prefix_errno("deflateInit");
 		if  (zerr == Z_MEM_ERROR) {
 			errno = ENOMEM;
-			return got_error_from_errno();
+			return got_error_prefix_errno("deflateInit");
 		}
 		return got_error(GOT_ERR_COMPRESSION);
 	}
@@ -59,7 +59,7 @@ got_deflate_init(struct got_deflate_buf *zb, uint8_t *
 
 	zb->inbuf = calloc(1, zb->inlen);
 	if (zb->inbuf == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("calloc");
 		goto done;
 	}
 
@@ -67,7 +67,7 @@ got_deflate_init(struct got_deflate_buf *zb, uint8_t *
 	if (outbuf == NULL) {
 		zb->outbuf = calloc(1, zb->outlen);
 		if (zb->outbuf == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("calloc");
 			goto done;
 		}
 		zb->flags |= GOT_DEFLATE_F_OWN_OUTBUF;
blob - c4bed1896f0d4b8f8e0c3d1f5b4629b46371abfe
blob + ecf6c0c261edbaf1cf5ae722612ff9a3662b761c
--- lib/delta.c
+++ lib/delta.c
@@ -187,7 +187,7 @@ static const struct got_error *
 copy_from_base(FILE *base_file, off_t offset, size_t size, FILE *outfile)
 {
 	if (fseeko(base_file, offset, SEEK_SET) != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("fseeko");
 
 	while (size > 0) {
 		uint8_t data[2048];
@@ -391,7 +391,7 @@ got_delta_apply(FILE *base_file, const uint8_t *delta_
 
 	if (memstream != NULL) {
 		if (fclose(memstream) != 0)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fclose");
 		if (err == NULL) {
 			size_t n;
 			n = fwrite(memstream_buf, 1, memstream_size, outfile);
blob - 8563f7894b512bf056774c692ac717124855bc9a
blob + 52b0c876d15b2cc0cd2b50756652b61ded1a1258
--- lib/diff.c
+++ lib/diff.c
@@ -54,14 +54,14 @@ diff_blobs(struct got_blob_object *blob1, struct got_b
 	if (blob1) {
 		f1 = got_opentemp();
 		if (f1 == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno("got_opentemp");
 	} else
 		flags |= D_EMPTY1;
 
 	if (blob2) {
 		f2 = got_opentemp();
 		if (f2 == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("got_opentemp");
 			fclose(f1);
 			return err;
 		}
@@ -112,9 +112,9 @@ diff_blobs(struct got_blob_object *blob1, struct got_b
 	err = got_diffreg(&res, f1, f2, flags, &args, &ds, outfile, changes);
 done:
 	if (f1 && fclose(f1) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	if (f2 && fclose(f2) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	return err;
 }
 
@@ -143,7 +143,7 @@ got_diff_blob_file(struct got_blob_object *blob1, FILE
 	if (blob1) {
 		f1 = got_opentemp();
 		if (f1 == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno("got_opentemp");
 		idstr1 = got_object_blob_id_str(blob1, hex1, sizeof(hex1));
 		err = got_object_blob_dump_to_file(&size1, NULL, f1, blob1);
 		if (err)
@@ -179,7 +179,7 @@ got_diff_blob_file(struct got_blob_object *blob1, FILE
 	err = got_diffreg(&res, f1, f2, flags, &args, &ds, outfile, NULL);
 done:
 	if (f1 && fclose(f1) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	return err;
 }
 
@@ -191,7 +191,7 @@ got_diff_blob_lines_changed(struct got_diff_changes **
 
 	*changes = calloc(1, sizeof(**changes));
 	if (*changes == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 	SIMPLEQ_INIT(&(*changes)->entries);
 
 	err = diff_blobs(blob1, blob2, NULL, NULL, 3, NULL, *changes);
@@ -513,7 +513,7 @@ got_diff_tree(struct got_tree_object *tree1, struct go
 		te1 = SIMPLEQ_FIRST(&entries->head);
 		if (te1 && asprintf(&l1, "%s%s%s", label1, label1[0] ? "/" : "",
 		    te1->name) == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("asprintf");
 	}
 	if (tree2) {
 		const struct got_tree_entries *entries;
@@ -521,7 +521,7 @@ got_diff_tree(struct got_tree_object *tree1, struct go
 		te2 = SIMPLEQ_FIRST(&entries->head);
 		if (te2 && asprintf(&l2, "%s%s%s", label2, label2[0] ? "/" : "",
 		    te2->name) == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("asprintf");
 	}
 
 	do {
@@ -534,7 +534,8 @@ got_diff_tree(struct got_tree_object *tree1, struct go
 				l2 = NULL;
 				if (te && asprintf(&l2, "%s%s%s", label2,
 				    label2[0] ? "/" : "", te->name) == -1)
-					return got_error_from_errno();
+					return
+					    got_error_prefix_errno("asprintf");
 			}
 			err = diff_entry_old_new(te1, te, l1, l2, diff_context,
 			    repo, outfile);
@@ -550,11 +551,13 @@ got_diff_tree(struct got_tree_object *tree1, struct go
 			if (te) {
 				if (asprintf(&l2, "%s%s%s", label2,
 				    label2[0] ? "/" : "", te->name) == -1)
-					return got_error_from_errno();
+					return
+					    got_error_prefix_errno("asprintf");
 			} else {
 				if (asprintf(&l2, "%s%s%s", label2,
 				    label2[0] ? "/" : "", te2->name) == -1)
-					return got_error_from_errno();
+					return
+					    got_error_prefix_errno("asprintf");
 			}
 			err = diff_entry_new_old(te2, te, l2, diff_context,
 			    repo, outfile);
@@ -569,7 +572,7 @@ got_diff_tree(struct got_tree_object *tree1, struct go
 			if (te1 &&
 			    asprintf(&l1, "%s%s%s", label1,
 			    label1[0] ? "/" : "", te1->name) == -1)
-				return got_error_from_errno();
+				return got_error_prefix_errno("asprintf");
 		}
 		free(l2);
 		l2 = NULL;
@@ -578,7 +581,7 @@ got_diff_tree(struct got_tree_object *tree1, struct go
 			if (te2 &&
 			    asprintf(&l2, "%s%s%s", label2,
 			        label2[0] ? "/" : "", te2->name) == -1)
-				return got_error_from_errno();
+				return got_error_prefix_errno("asprintf");
 		}
 	} while (te1 || te2);
 
blob - a2506ec7ba196408a1cdebbeb132c449b2d5032f
blob + 8c259646842fa5061eae66ddd6cb0663f52071cb
--- lib/diff3.c
+++ lib/diff3.c
@@ -185,7 +185,7 @@ diff_output(BUF *diffbuf, const char *fmt, ...)
 	i = vasprintf(&str, fmt, vap);
 	va_end(vap);
 	if (i == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("vasprintf");
 	buf_append(&newsize, diffbuf, str, strlen(str));
 	free(str);
 	return NULL;
@@ -205,12 +205,12 @@ diffreg(BUF **d, const char *path1, const char *path2)
 
 	f1 = fopen(path1, "r");
 	if (f1 == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("fopen", path1);
 		goto done;
 	}
 	f2 = fopen(path2, "r");
 	if (f1 == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("fopen", path2);
 		goto done;
 	}
 
@@ -221,11 +221,11 @@ diffreg(BUF **d, const char *path1, const char *path2)
 	memset(&ds, 0, sizeof(ds));
 	/* XXX should stat buffers be passed in args instead of ds? */
 	if (stat(path1, &ds.stb1) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("stat", path1);
 		goto done;
 	}
 	if (stat(path2, &ds.stb2) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("stat", path2);
 		goto done;
 	}
 
@@ -241,24 +241,24 @@ diffreg(BUF **d, const char *path1, const char *path2)
 		goto done;
 
 	if (fflush(outfile) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("fflush", outpath);
 		goto done;
 	}
 
 	*d = buf_load(outpath);
 	if (*d == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("buf_load");
 done:
 	if (outpath) {
 		unlink(outpath);
 		free(outpath);
 	}
 	if (outfile && fclose(outfile) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	if (f1 && fclose(f1) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	if (f2 && fclose(f2) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	return err;
 }
 
@@ -284,7 +284,7 @@ got_merge_diff3(int *overlapcnt, int outfd, const char
 
 	d3s = calloc(1, sizeof(*d3s));
 	if (d3s == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 	d3s->eflag = 3; /* default -E for compatibility with former RCS */
 	d3s->oflag = 1; /* default -E for compatibility with former RCS */
 
@@ -302,15 +302,15 @@ got_merge_diff3(int *overlapcnt, int outfd, const char
 	diffb = buf_alloc(128);
 
 	if (asprintf(&path1, "/tmp/got-diff1.XXXXXXXX") == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto out;
 	}
 	if (asprintf(&path2, "/tmp/got-diff2.XXXXXXXX") == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto out;
 	}
 	if (asprintf(&path3, "/tmp/got-diff3.XXXXXXXX") == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto out;
 	}
 
@@ -342,7 +342,7 @@ got_merge_diff3(int *overlapcnt, int outfd, const char
 	}
 
 	if (asprintf(&dp13, "/tmp/got-d13.XXXXXXXXXX") == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto out;
 	}
 	err = buf_write_stmp(d1, dp13, &temp_files);
@@ -353,7 +353,7 @@ got_merge_diff3(int *overlapcnt, int outfd, const char
 	d1 = NULL;
 
 	if (asprintf(&dp23, "/tmp/got-d23.XXXXXXXXXX") == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto out;
 	}
 	err = buf_write_stmp(d2, dp23, &temp_files);
@@ -402,11 +402,11 @@ out:
 
 	for (i = 0; i < nitems(d3s->fp); i++) {
 		if (d3s->fp[i] && fclose(d3s->fp[i]) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fclose");
 	}
 	if (err == NULL && diffb) {
 		if (buf_write_fd(diffb, outfd) < 0)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("buf_write_fd");
 		*overlapcnt = d3s->overlapcnt;
 	}
 	free(d3s);
@@ -445,14 +445,14 @@ diff3_internal(char *dp13, char *dp23, char *path1, ch
 		return err;
 
 	if ((d3s->fp[0] = fopen(path1, "r")) == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("fopen", path1);
 	if ((d3s->fp[1] = fopen(path2, "r")) == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("fopen", path2);
 	if ((d3s->fp[2] = fopen(path3, "r")) == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("fopen", path3);
 
 	if (merge(m, n, d3s) < 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("merge");
 	return NULL;
 }
 
@@ -585,7 +585,7 @@ readin(size_t *n, char *name, struct diff **dd, struct
 
 	d3s->fp[0] = fopen(name, "r");
 	if (d3s->fp[0] == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("fopen", name);
 	for (i = 0; (p = getchange(d3s->fp[0], d3s)); i++) {
 		if (i >= d3s->szchanges - 1) {
 			err = increase(d3s);
@@ -621,7 +621,7 @@ readin(size_t *n, char *name, struct diff **dd, struct
 	}
 
 	if (fclose(d3s->fp[0]) != 0)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 
 	*n = i;
 	return err;
@@ -982,25 +982,25 @@ increase(struct diff3_state *d3s)
 
 	d = reallocarray(d3s->d13, newsz, sizeof(*d3s->d13));
 	if (d == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("reallocarray");
 	d3s->d13 = d;
 	memset(d3s->d13 + d3s->szchanges, 0, incr * sizeof(*d3s->d13));
 
 	d = reallocarray(d3s->d23, newsz, sizeof(*d3s->d23));
 	if (d == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("reallocarray");
 	d3s->d23 = d;
 	memset(d3s->d23 + d3s->szchanges, 0, incr * sizeof(*d3s->d23));
 
 	d = reallocarray(d3s->de, newsz, sizeof(*d3s->de));
 	if (d == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("reallocarray");
 	d3s->de = d;
 	memset(d3s->de + d3s->szchanges, 0, incr * sizeof(*d3s->de));
 
 	s = reallocarray(d3s->overlap, newsz, sizeof(*d3s->overlap));
 	if (s == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("reallocarray");
 	d3s->overlap = s;
 	memset(d3s->overlap + d3s->szchanges, 0, incr * sizeof(*d3s->overlap));
 	d3s->szchanges = newsz;
blob - 6d1af1ad443cf2c9732c10f711a9708c952f4a0e
blob + 87f54533f4efc138efcb8ffe4b2043bae52623cd
--- lib/diffoffset.c
+++ lib/diffoffset.c
@@ -64,11 +64,11 @@ got_diffoffset_alloc(struct got_diffoffset_chunks **ch
 
 	first = alloc_chunk(0, 0);
 	if (first == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("alloc_chunk");
 
 	*chunks = calloc(1, sizeof(**chunks));
 	if (*chunks == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("calloc");
 		free(first);
 		return err;
 	}
@@ -100,12 +100,13 @@ got_diffoffset_add(struct got_diffoffset_chunks *chunk
 
 	chunk1 = alloc_chunk(old_lineno, new_lineno - old_lineno);
 	if (chunk1 == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("alloc_chunk");
 
 	chunk2 = alloc_chunk(old_lineno + old_length,
 	    new_lineno - old_lineno + new_length - old_length);
 	if (chunk2 == NULL) {
-		const struct got_error *err = got_error_from_errno();
+		const struct got_error *err =
+		    got_error_prefix_errno("alloc_chunk");
 		free(chunk1);
 		return err;
 	}
blob - 221240810d6f6764a3b02ed81bb2f833ffb103b0
blob + fa4938c7bfaefec7a8494a0d6081ac999207a3e8
--- lib/diffreg.c
+++ lib/diffreg.c
@@ -293,7 +293,7 @@ got_diffreg(int *rval, FILE *f1, FILE *f2, int flags,
 	if (flags & D_EMPTY1) {
 		f1 = fopen(_PATH_DEVNULL, "r");
 		if (f1 == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("fopen", _PATH_DEVNULL);
 			goto closem;
 		}
 	}
@@ -305,7 +305,7 @@ got_diffreg(int *rval, FILE *f1, FILE *f2, int flags,
 	if (flags & D_EMPTY2) {
 		f2 = fopen(_PATH_DEVNULL, "r");
 		if (f2 == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("fopen", _PATH_DEVNULL);
 			goto closem;
 		}
 	} else if (f2 == NULL) {
@@ -331,11 +331,11 @@ got_diffreg(int *rval, FILE *f1, FILE *f2, int flags,
 		goto closem;
 	}
 	if (prepare(ds, 0, f1, ds->stb1.st_size, flags)) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("prepare");
 		goto closem;
 	}
 	if (prepare(ds, 1, f2, ds->stb2.st_size, flags)) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("prepare");
 		goto closem;
 	}
 
@@ -347,44 +347,44 @@ got_diffreg(int *rval, FILE *f1, FILE *f2, int flags,
 	equiv(ds->sfile[0], ds->slen[0], ds->sfile[1], ds->slen[1], ds->member);
 	p = reallocarray(ds->member, ds->slen[1] + 2, sizeof(*ds->member));
 	if (p == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("reallocarray");
 		goto closem;
 	}
 	ds->member = p;
 
 	ds->class = (int *)ds->file[0];
 	if (unsort(ds->sfile[0], ds->slen[0], ds->class)) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("unsort");
 		goto closem;
 	}
 	p = reallocarray(ds->class, ds->slen[0] + 2, sizeof(*ds->class));
 	if (p == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("reallocarray");
 		goto closem;
 	}
 	ds->class = p;
 
 	ds->klist = calloc(ds->slen[0] + 2, sizeof(*ds->klist));
 	if (ds->klist == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("calloc");
 		goto closem;
 	}
 	ds->clen = 0;
 	ds->clistlen = 100;
 	ds->clist = calloc(ds->clistlen, sizeof(*ds->clist));
 	if (ds->clist == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("calloc");
 		goto closem;
 	}
 	i = stone(ds, ds->class, ds->slen[0], ds->member, ds->klist, flags);
 	if (i < 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("stone");
 		goto closem;
 	}
 
 	p = reallocarray(ds->J, ds->len[0] + 2, sizeof(*ds->J));
 	if (p == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("reallocarray");
 		goto closem;
 	}
 	ds->J = p;
@@ -392,20 +392,20 @@ got_diffreg(int *rval, FILE *f1, FILE *f2, int flags,
 
 	lp = reallocarray(ds->ixold, ds->len[0] + 2, sizeof(*ds->ixold));
 	if (lp == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("reallocarray");
 		goto closem;
 	}
 	ds->ixold = lp;
 	lp = reallocarray(ds->ixnew, ds->len[1] + 2, sizeof(*ds->ixnew));
 	if (lp == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("reallocarray");
 		goto closem;
 	}
 	ds->ixnew = lp;
 	check(ds, f1, f2, flags);
 	if (output(outfile, changes, ds, args, args->label[0], f1,
 	    args->label[1], f2, flags))
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("output");
 closem:
 	free(ds->J);
 	free(ds->member);
blob - bb4d6fe2b481570d5cfbdd728ea7e4e291c9bc26
blob + 4936ab52ab920adbc7c55b286edd1676c86d9fbe
--- lib/error.c
+++ lib/error.c
@@ -68,22 +68,26 @@ got_error_msg(int code, const char *msg)
 }
 
 const struct got_error *
-got_error_from_errno(void)
+got_error_prefix_errno(const char *prefix)
 {
 	static struct got_error err;
+	static char err_msg[MAXPATHLEN + 20];
 
+	snprintf(err_msg, sizeof(err_msg), "%s: %s", prefix,
+	    strerror(errno));
+
 	err.code = GOT_ERR_ERRNO;
-	err.msg = strerror(errno);
+	err.msg = err_msg;
 	return &err;
 }
 
 const struct got_error *
-got_error_prefix_errno(const char *prefix)
+got_error_prefix_errno2(const char *prefix, const char *prefix2)
 {
 	static struct got_error err;
-	static char err_msg[MAXPATHLEN + 20];
+	static char err_msg[(MAXPATHLEN * 2) + 20];
 
-	snprintf(err_msg, sizeof(err_msg), "%s: %s", prefix,
+	snprintf(err_msg, sizeof(err_msg), "%s: %s: %s", prefix, prefix2,
 	    strerror(errno));
 
 	err.code = GOT_ERR_ERRNO;
@@ -92,17 +96,32 @@ got_error_prefix_errno(const char *prefix)
 }
 
 const struct got_error *
+got_error_prefix_errno3(const char *prefix, const char *prefix2,
+    const char *prefix3)
+{
+	static struct got_error err;
+	static char err_msg[(MAXPATHLEN * 3) + 20];
+
+	snprintf(err_msg, sizeof(err_msg), "%s: %s: %s: %s", prefix, prefix2,
+	    prefix3, strerror(errno));
+
+	err.code = GOT_ERR_ERRNO;
+	err.msg = err_msg;
+	return &err;
+}
+
+const struct got_error *
 got_error_set_errno(int code)
 {
 	errno = code;
-	return got_error_from_errno();
+	return got_error_prefix_errno("");
 }
 
 const struct got_error *
 got_ferror(FILE *f, int code)
 {
 	if (ferror(f))
-		return got_error_from_errno();
+		return got_error_prefix_errno("");
 	return got_error(code);
 }
 
blob - a30b4cfe7f85f2d82af4af74ce41f45aa9f9c9e2
blob + f42c329a6c1c86507f5d659aa66a06bf6cfa7d15
--- lib/fileindex.c
+++ lib/fileindex.c
@@ -59,7 +59,7 @@ got_fileindex_entry_update(struct got_fileindex_entry 
 
 	if (lstat(ondisk_path, &sb) != 0) {
 		if ((entry->flags & GOT_FILEIDX_F_NO_FILE_ON_DISK) == 0)
-			return got_error_from_errno();
+			return got_error_prefix_errno2("lstat", ondisk_path);
 	} else
 		entry->flags &= ~GOT_FILEIDX_F_NO_FILE_ON_DISK;
 
@@ -111,11 +111,11 @@ got_fileindex_entry_alloc(struct got_fileindex_entry *
 
 	*entry = calloc(1, sizeof(**entry));
 	if (*entry == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	(*entry)->path = strdup(relpath);
 	if ((*entry)->path == NULL) {
-		const struct got_error *err = got_error_from_errno();
+		const struct got_error *err = got_error_prefix_errno("strdup");
 		free(*entry);
 		*entry = NULL;
 		return err;
@@ -389,7 +389,7 @@ got_fileindex_write(struct got_fileindex *fileindex, F
 		return got_ferror(outfile, GOT_ERR_IO);
 
 	if (fflush(outfile) != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("fflush");
 
 	return NULL;
 }
@@ -442,7 +442,7 @@ read_fileindex_path(char **path, SHA1_CTX *ctx, FILE *
 
 	*path = malloc(totlen);
 	if (*path == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 
 	do {
 		n = fread(buf, 1, sizeof(buf), infile);
@@ -451,7 +451,7 @@ read_fileindex_path(char **path, SHA1_CTX *ctx, FILE *
 		if (len + sizeof(buf) > totlen) {
 			char *p = reallocarray(*path, totlen + sizeof(buf), 1);
 			if (p == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("reallocarray");
 				break;
 			}
 			totlen += sizeof(buf);
@@ -481,7 +481,7 @@ read_fileindex_entry(struct got_fileindex_entry **entr
 
 	entry = calloc(1, sizeof(*entry));
 	if (entry == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	err = read_fileindex_val64(&entry->ctime_sec, ctx, infile);
 	if (err)
@@ -635,7 +635,7 @@ walk_tree(struct got_tree_entry **next, struct got_fil
 
 		if (asprintf(&subpath, "%s%s%s", path,
 		    path[0] == '\0' ? "" : "/", te->name) == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("asprintf");
 
 		err = got_object_open_as_tree(&subtree, repo, te->id);
 		if (err) {
@@ -674,7 +674,7 @@ diff_fileindex_tree(struct got_fileindex *fileindex,
 			char *te_path;
 			int cmp;
 			if (asprintf(&te_path, "%s/%s", path, te->name) == -1) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("asprintf");
 				break;
 			}
 			cmp = got_path_cmp((*ie)->path, te_path);
@@ -776,18 +776,18 @@ walk_dir(struct got_pathlist_entry **next, struct got_
 
 		if (asprintf(&subpath, "%s%s%s", path,
 		    path[0] == '\0' ? "" : "/", de->d_name) == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("asprintf");
 
 		if (asprintf(&subdirpath, "%s/%s", rootpath, subpath) == -1) {
 			free(subpath);
-			return got_error_from_errno();
+			return got_error_prefix_errno("asprintf");
 		}
 
 		subdir = opendir(subdirpath);
 		if (subdir == NULL) {
 			free(subpath);
 			free(subdirpath);
-			return got_error_from_errno();
+			return got_error_prefix_errno2("opendir", subdirpath);
 		}
 
 		err = diff_fileindex_dir(fileindex, ie, subdir, rootpath,
@@ -824,12 +824,12 @@ diff_fileindex_dir(struct got_fileindex *fileindex,
 
 		de = malloc(sizeof(struct dirent) + NAME_MAX + 1);
 		if (de == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("malloc");
 			goto done;
 		}
 
 		if (readdir_r(dir, de, &dep) != 0) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("readdir_r");
 			free(de);
 			goto done;
 		}
@@ -866,7 +866,7 @@ diff_fileindex_dir(struct got_fileindex *fileindex,
 			de = dle->data;
 			if (asprintf(&de_path, "%s/%s", path,
 			    de->d_name) == -1) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("asprintf");
 				break;
 			}
 			cmp = got_path_cmp((*ie)->path, de_path);
blob - bd403961e91efebbe3b1c417dae2da911d752c55
blob + a23e868b2e9cfcfec8cd0909dd3a4d76eb28ab23
--- lib/inflate.c
+++ lib/inflate.c
@@ -47,10 +47,10 @@ got_inflate_init(struct got_inflate_buf *zb, uint8_t *
 	zerr = inflateInit(&zb->z);
 	if (zerr != Z_OK) {
 		if  (zerr == Z_ERRNO)
-			return got_error_from_errno();
+			return got_error_prefix_errno("inflateInit");
 		if  (zerr == Z_MEM_ERROR) {
 			errno = ENOMEM;
-			return got_error_from_errno();
+			return got_error_prefix_errno("inflateInit");
 		}
 		return got_error(GOT_ERR_DECOMPRESSION);
 	}
@@ -59,7 +59,7 @@ got_inflate_init(struct got_inflate_buf *zb, uint8_t *
 
 	zb->inbuf = calloc(1, zb->inlen);
 	if (zb->inbuf == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("calloc");
 		goto done;
 	}
 
@@ -67,7 +67,7 @@ got_inflate_init(struct got_inflate_buf *zb, uint8_t *
 	if (outbuf == NULL) {
 		zb->outbuf = calloc(1, zb->outlen);
 		if (zb->outbuf == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("calloc");
 			goto done;
 		}
 		zb->flags |= GOT_INFLATE_F_OWN_OUTBUF;
@@ -134,7 +134,7 @@ got_inflate_read_fd(struct got_inflate_buf *zb, int fd
 		if (z->avail_in == 0) {
 			ssize_t n = read(fd, zb->inbuf, zb->inlen);
 			if (n < 0)
-				return got_error_from_errno();
+				return got_error_prefix_errno("read");
 			else if (n == 0) {
 				/* EOF */
 				ret = Z_STREAM_END;
@@ -220,7 +220,7 @@ got_inflate_to_mem(uint8_t **outbuf, size_t *outlen, F
 
 	*outbuf = calloc(1, GOT_INFLATE_BUFSIZE);
 	if (*outbuf == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 	err = got_inflate_init(&zb, *outbuf, GOT_INFLATE_BUFSIZE);
 	if (err)
 		return err;
@@ -237,7 +237,7 @@ got_inflate_to_mem(uint8_t **outbuf, size_t *outlen, F
 			newbuf = recallocarray(*outbuf, nbuf - 1, nbuf,
 			   GOT_INFLATE_BUFSIZE);
 			if (newbuf == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("recallocarray");
 				free(*outbuf);
 				*outbuf = NULL;
 				*outlen = 0;
@@ -265,7 +265,7 @@ got_inflate_to_mem_fd(uint8_t **outbuf, size_t *outlen
 
 	*outbuf = calloc(1, GOT_INFLATE_BUFSIZE);
 	if (*outbuf == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 	err = got_inflate_init(&zb, *outbuf, GOT_INFLATE_BUFSIZE);
 	if (err)
 		goto done;
@@ -282,7 +282,7 @@ got_inflate_to_mem_fd(uint8_t **outbuf, size_t *outlen
 			newbuf = recallocarray(*outbuf, nbuf - 1, nbuf,
 			    GOT_INFLATE_BUFSIZE);
 			if (newbuf == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("recallocarray");
 				free(*outbuf);
 				*outbuf = NULL;
 				*outlen = 0;
@@ -311,7 +311,7 @@ got_inflate_to_mem_mmap(uint8_t **outbuf, size_t *outl
 
 	*outbuf = calloc(1, GOT_INFLATE_BUFSIZE);
 	if (*outbuf == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 	err = got_inflate_init(&zb, *outbuf, GOT_INFLATE_BUFSIZE);
 	if (err) {
 		free(*outbuf);
@@ -336,7 +336,7 @@ got_inflate_to_mem_mmap(uint8_t **outbuf, size_t *outl
 			newbuf = recallocarray(*outbuf, nbuf - 1, nbuf,
 			    GOT_INFLATE_BUFSIZE);
 			if (newbuf == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("recallocarray");
 				free(*outbuf);
 				*outbuf = NULL;
 				*outlen = 0;
@@ -373,7 +373,7 @@ got_inflate_to_fd(size_t *outlen, FILE *infile, int ou
 			ssize_t n;
 			n = write(outfd, zb.outbuf, avail);
 			if (n != avail) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("write");
 				goto done;
 			}
 			*outlen += avail;
@@ -383,7 +383,7 @@ got_inflate_to_fd(size_t *outlen, FILE *infile, int ou
 done:
 	if (err == NULL) {
 		if (lseek(outfd, SEEK_SET, 0) == -1)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("lseek");
 	}
 	got_inflate_end(&zb);
 	return err;
blob - 0426e42d52de29293430223cc643f1687b0f5372
blob + 9c2a16b3b0c849368cfbbf4060db8bf432199e77
--- lib/lockfile.c
+++ lib/lockfile.c
@@ -38,17 +38,17 @@ got_lockfile_lock(struct got_lockfile **lf, const char
 
 	*lf = calloc(1, sizeof(**lf));
 	if (*lf == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 	(*lf)->fd = -1;
 
 	(*lf)->locked_path = strdup(path);
 	if ((*lf)->locked_path == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		goto done;
 	}
 
 	if (asprintf(&(*lf)->path, "%s%s", path, GOT_LOCKFILE_SUFFIX) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 
@@ -59,7 +59,7 @@ got_lockfile_lock(struct got_lockfile **lf, const char
 		if ((*lf)->fd != -1)
 			break;
 		if (errno != EEXIST) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("open", (*lf)->path);
 			goto done;
 		}
 		sleep(1);
@@ -81,9 +81,9 @@ got_lockfile_unlock(struct got_lockfile *lf)
 	const struct got_error *err = NULL;
 
 	if (lf->path && lf->fd != -1 && unlink(lf->path) != 0)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("unlink");
 	if (lf->fd != -1 && close(lf->fd) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	free(lf->path);
 	free(lf->locked_path);
 	free(lf);
blob - 8c71dc8c1c85d1c0e244dee4252aeebc06044c4c
blob + 0c9e8d05afb85118159e6aee19002ca969c23612
--- lib/object.c
+++ lib/object.c
@@ -146,7 +146,7 @@ open_loose_object(int *fd, struct got_object_id *id,
 		return err;
 	*fd = open(path, O_RDONLY | O_NOFOLLOW);
 	if (*fd == -1) {
-		err = got_error_prefix_errno(path);
+		err = got_error_prefix_errno2("open", path);
 		goto done;
 	}
 done:
@@ -263,7 +263,7 @@ start_pack_privsep_child(struct got_pack *pack, struct
 	}
 
 	if (close(imsg_fds[1]) != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("close");
 	pack->privsep_child->imsg_fd = imsg_fds[0];
 	pack->privsep_child->pid = pid;
 	imsg_init(ibuf, imsg_fds[0]);
@@ -383,7 +383,7 @@ read_object_header_privsep(struct got_object **obj, st
 	}
 
 	if (close(imsg_fds[1]) != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("close");
 	repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].imsg_fd =
 	    imsg_fds[0];
 	repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].pid = pid;
@@ -425,7 +425,7 @@ got_object_open(struct got_object **obj, struct got_re
 		if (errno == ENOENT)
 			err = got_error_no_obj(id);
 		else
-			err = got_error_prefix_errno(path);
+			err = got_error_prefix_errno2("open", path);
 		goto done;
 	} else {
 		err = read_object_header_privsep(obj, repo, fd);
@@ -548,7 +548,7 @@ read_commit_privsep(struct got_commit_object **commit,
 	}
 
 	if (close(imsg_fds[1]) != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("close");
 	repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].imsg_fd =
 	    imsg_fds[0];
 	repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].pid = pid;
@@ -726,7 +726,7 @@ read_tree_privsep(struct got_tree_object **tree, int o
 	}
 
 	if (close(imsg_fds[1]) != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("close");
 	repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].imsg_fd =
 	    imsg_fds[0];
 	repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].pid = pid;
@@ -946,7 +946,7 @@ read_blob_privsep(uint8_t **outbuf, size_t *size, size
 	}
 
 	if (close(imsg_fds[1]) != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("close");
 	repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].imsg_fd =
 	    imsg_fds[0];
 	repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].pid = pid;
@@ -1019,7 +1019,7 @@ open_blob(struct got_blob_object **blob, struct got_re
 
 	if (outbuf) {
 		if (close(outfd) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("close");
 		outfd = -1;
 		(*blob)->f = fmemopen(outbuf, size, "rb");
 		if ((*blob)->f == NULL) {
@@ -1084,7 +1084,7 @@ got_object_blob_close(struct got_blob_object *blob)
 	const struct got_error *err = NULL;
 	free(blob->read_buf);
 	if (blob->f && fclose(blob->f) != 0)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	free(blob->data);
 	free(blob);
 	return err;
@@ -1239,7 +1239,7 @@ read_tag_privsep(struct got_tag_object **tag, int obj_
 	}
 
 	if (close(imsg_fds[1]) != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("close");
 	repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TAG].imsg_fd =
 	    imsg_fds[0];
 	repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TAG].pid = pid;
blob - 63b2ca2a42f301ea74c82bfe070daf1cf71508ab
blob + 17731e448a0b3bfaf078194ce96ece804815b588
--- lib/object_cache.c
+++ lib/object_cache.c
@@ -45,7 +45,7 @@ got_object_cache_init(struct got_object_cache *cache,
 
 	cache->idset = got_object_idset_alloc();
 	if (cache->idset == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("got_object_idset_alloc");
 
 	cache->type = type;
 	switch (type) {
@@ -98,7 +98,7 @@ got_object_cache_add(struct got_object_cache *cache, s
 
 	ce = malloc(sizeof(*ce));
 	if (ce == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 	memcpy(&ce->id, id, sizeof(ce->id));
 	switch (cache->type) {
 	case GOT_OBJECT_CACHE_TYPE_OBJ:
blob - a3dbc82a22f6ebf95eaf48fb75437c549011c14d
blob + 713cdf2845f8ec504efd54c7c91eeffcfc84df0b
--- lib/object_create.c
+++ lib/object_create.c
@@ -84,25 +84,25 @@ create_object_file(struct got_object_id *id, FILE *con
 		goto done;
 
 	if (rename(tmppath, objpath) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno3("rename", tmppath, objpath);
 		goto done;
 	}
 	free(tmppath);
 	tmppath = NULL;
 
 	if (chmod(objpath, GOT_DEFAULT_FILE_MODE) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("chmod", objpath);
 		goto done;
 	}
 done:
 	free(objpath);
 	if (tmppath) {
 		if (unlink(tmppath) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("unlink", tmppath);
 		free(tmppath);
 	}
 	if (tmpfile && fclose(tmpfile) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	if (lf)
 		unlock_err = got_lockfile_unlock(lf);
 	return err ? err : unlock_err;
@@ -126,16 +126,16 @@ got_object_blob_create(struct got_object_id **id, cons
 
 	fd = open(ondisk_path, O_RDONLY | O_NOFOLLOW);
 	if (fd == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("open", ondisk_path);
 
 	if (fstat(fd, &sb) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("fstat", ondisk_path);
 		goto done;
 	}
 
 	if (asprintf(&header, "%s %lld", GOT_OBJ_LABEL_BLOB,
 		sb.st_size) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 	headerlen = strlen(header) + 1;
@@ -143,7 +143,7 @@ got_object_blob_create(struct got_object_id **id, cons
 
 	blobfile = got_opentemp();
 	if (blobfile == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_opentemp");
 		goto done;
 	}
 
@@ -158,7 +158,7 @@ got_object_blob_create(struct got_object_id **id, cons
 
 		inlen = read(fd, buf, sizeof(buf));
 		if (inlen == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("read");
 			goto done;
 		}
 		if (inlen == 0)
@@ -173,13 +173,13 @@ got_object_blob_create(struct got_object_id **id, cons
 
 	*id = malloc(sizeof(**id));
 	if (*id == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("malloc");
 		goto done;
 	}
 	SHA1Final((*id)->sha1, &sha1_ctx);
 
 	if (fflush(blobfile) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fflush");
 		goto done;
 	}
 	rewind(blobfile);
@@ -188,9 +188,9 @@ got_object_blob_create(struct got_object_id **id, cons
 done:
 	free(header);
 	if (fd != -1 && close(fd) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	if (blobfile && fclose(blobfile) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	if (err) {
 		free(*id);
 		*id = NULL;
@@ -233,7 +233,7 @@ got_object_tree_create(struct got_object_id **id,
 	}
 
 	if (asprintf(&header, "%s %zd", GOT_OBJ_LABEL_TREE, len) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 	headerlen = strlen(header) + 1;
@@ -241,7 +241,7 @@ got_object_tree_create(struct got_object_id **id,
 
 	treefile = got_opentemp();
 	if (treefile == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_opentemp");
 		goto done;
 	}
 
@@ -282,13 +282,13 @@ got_object_tree_create(struct got_object_id **id,
 
 	*id = malloc(sizeof(**id));
 	if (*id == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("malloc");
 		goto done;
 	}
 	SHA1Final((*id)->sha1, &sha1_ctx);
 
 	if (fflush(treefile) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fflush");
 		goto done;
 	}
 	rewind(treefile);
@@ -297,7 +297,7 @@ got_object_tree_create(struct got_object_id **id,
 done:
 	free(header);
 	if (treefile && fclose(treefile) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	if (err) {
 		free(*id);
 		*id = NULL;
@@ -327,13 +327,13 @@ got_object_commit_create(struct got_object_id **id,
 
 	if (asprintf(&author_str, "%s%s %lld +0000\n",
 	    GOT_COMMIT_LABEL_AUTHOR, author, author_time) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("asprintf");
 
 	if (asprintf(&committer_str, "%s%s %lld +0000\n",
 	    GOT_COMMIT_LABEL_COMMITTER, committer ? committer : author,
 	    committer ? committer_time : author_time)
 	    == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 
@@ -343,7 +343,7 @@ got_object_commit_create(struct got_object_id **id,
 	    + strlen(author_str) + strlen(committer_str) + 2 + strlen(logmsg);
 
 	if (asprintf(&header, "%s %zd", GOT_OBJ_LABEL_COMMIT, len) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 	headerlen = strlen(header) + 1;
@@ -351,7 +351,7 @@ got_object_commit_create(struct got_object_id **id,
 
 	commitfile = got_opentemp();
 	if (commitfile == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_opentemp");
 		goto done;
 	}
 
@@ -366,7 +366,7 @@ got_object_commit_create(struct got_object_id **id,
 		goto done;
 	if (asprintf(&tree_str, "%s%s\n", GOT_COMMIT_LABEL_TREE, id_str)
 	    == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 	len = strlen(tree_str);
@@ -387,7 +387,7 @@ got_object_commit_create(struct got_object_id **id,
 			goto done;
 		if (asprintf(&parent_str, "%s%s\n", GOT_COMMIT_LABEL_PARENT,
 		    id_str) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("asprintf");
 			goto done;
 		}
 		len = strlen(parent_str);
@@ -441,13 +441,13 @@ got_object_commit_create(struct got_object_id **id,
 
 	*id = malloc(sizeof(**id));
 	if (*id == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("malloc");
 		goto done;
 	}
 	SHA1Final((*id)->sha1, &sha1_ctx);
 
 	if (fflush(commitfile) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fflush");
 		goto done;
 	}
 	rewind(commitfile);
@@ -459,7 +459,7 @@ done:
 	free(author_str);
 	free(committer_str);
 	if (commitfile && fclose(commitfile) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	if (err) {
 		free(*id);
 		*id = NULL;
blob - b71b1c335861e5d63a9a6fcc321452f6767e95b5
blob + 70eab62f6e930e3ef292944cbc8c3dc8cb09f48f
--- lib/object_idset.c
+++ lib/object_idset.c
@@ -97,7 +97,7 @@ got_object_idset_add(struct got_object_idset *set, str
 
 	new = malloc(sizeof(*new));
 	if (new == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 
 	memcpy(&new->id, id, sizeof(new->id));
 	new->data = data;
blob - 8840c627c2b32e58972343d498577b2c050be4f2
blob + e152249c6afce606ed07fd63a05aa675fed43163
--- lib/object_parse.c
+++ lib/object_parse.c
@@ -68,11 +68,11 @@ got_object_qid_alloc_partial(struct got_object_qid **q
 
 	*qid = malloc(sizeof(**qid));
 	if (*qid == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 
 	(*qid)->id = malloc(sizeof(*((*qid)->id)));
 	if ((*qid)->id == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("malloc");
 		got_object_qid_free(*qid);
 		*qid = NULL;
 		return err;
@@ -88,7 +88,7 @@ got_object_id_str(char **outbuf, struct got_object_id 
 
 	*outbuf = malloc(len);
 	if (*outbuf == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 
 	if (got_sha1_digest_to_str(id->sha1, *outbuf, len) == NULL) {
 		free(*outbuf);
@@ -175,7 +175,7 @@ got_object_parse_header(struct got_object **obj, char 
 
 	*obj = calloc(1, sizeof(**obj));
 	if (*obj == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 	(*obj)->type = type;
 	(*obj)->hdrlen = hdrlen;
 	(*obj)->size = size;
@@ -196,7 +196,7 @@ got_object_read_header(struct got_object **obj, int fd
 
 	buf = malloc(zbsize);
 	if (buf == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 
 	err = got_inflate_init(&zb, buf, zbsize);
 	if (err)
@@ -215,7 +215,7 @@ got_object_read_header(struct got_object **obj, int fd
 			nbuf++;
 			newbuf = recallocarray(buf, nbuf - 1, nbuf, zbsize);
 			if (newbuf == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("recallocarray");
 				goto done;
 			}
 			buf = newbuf;
@@ -314,7 +314,7 @@ parse_commit_time(time_t *time, time_t *gmtoff, char *
 		return got_error(GOT_ERR_BAD_OBJ_DATA);
 	tzstr = strdup(space + 1);
 	if (tzstr == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("strdup");
 	err = parse_gmtoff(gmtoff, tzstr);
 	free(tzstr);
 	if (err)
@@ -431,10 +431,10 @@ got_object_parse_commit(struct got_commit_object **com
 	char *s = buf;
 	size_t label_len;
 	ssize_t remain = (ssize_t)len;
- 
+
 	*commit = got_object_commit_alloc_partial();
 	if (*commit == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("got_object_commit_alloc_partial");
 
 	label_len = strlen(GOT_COMMIT_LABEL_TREE);
 	if (strncmp(s, GOT_COMMIT_LABEL_TREE, label_len) == 0) {
@@ -495,7 +495,7 @@ got_object_parse_commit(struct got_commit_object **com
 			goto done;
 		(*commit)->author = strdup(s);
 		if ((*commit)->author == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("strdup");
 			goto done;
 		}
 		s += slen + 1;
@@ -526,7 +526,7 @@ got_object_parse_commit(struct got_commit_object **com
 			goto done;
 		(*commit)->committer = strdup(s);
 		if ((*commit)->committer == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("strdup");
 			goto done;
 		}
 		s += slen + 1;
@@ -535,7 +535,7 @@ got_object_parse_commit(struct got_commit_object **com
 
 	(*commit)->logmsg = strndup(s, remain);
 	if ((*commit)->logmsg == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strndup");
 		goto done;
 	}
 done:
@@ -605,7 +605,7 @@ parse_tree_entry(struct got_tree_entry **te, size_t *e
 
 	*te = got_alloc_tree_entry_partial();
 	if (*te == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("got_alloc_tree_entry_partial");
 
 	*elen = strnlen(buf, maxlen) + 1;
 	if (*elen > maxlen) {
@@ -661,7 +661,7 @@ got_object_parse_tree(struct got_tree_object **tree, u
 
 	*tree = calloc(1, sizeof(**tree));
 	if (*tree == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	SIMPLEQ_INIT(&(*tree)->entries.head);
 
@@ -720,7 +720,7 @@ got_object_parse_tag(struct got_tag_object **tag, uint
 
 	*tag = calloc(1, sizeof(**tag));
 	if (*tag == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	label_len = strlen(GOT_TAG_LABEL_OBJECT);
 	if (strncmp(s, GOT_TAG_LABEL_OBJECT, label_len) == 0) {
@@ -817,7 +817,7 @@ got_object_parse_tag(struct got_tag_object **tag, uint
 		slen = strlen(s);
 		(*tag)->tag = strndup(s, slen);
 		if ((*tag)->tag == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("strndup");
 			goto done;
 		}
 		s += slen + 1;
@@ -855,7 +855,7 @@ got_object_parse_tag(struct got_tag_object **tag, uint
 			goto done;
 		(*tag)->tagger = strdup(s);
 		if ((*tag)->tagger == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("strdup");
 			goto done;
 		}
 		s += slen + 1;
@@ -868,14 +868,14 @@ got_object_parse_tag(struct got_tag_object **tag, uint
 		/* Some old tags in the Linux git repo have no tagger. */
 		(*tag)->tagger = strdup("");
 		if ((*tag)->tagger == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("strdup");
 			goto done;
 		}
 	}
 
 	(*tag)->tagmsg = strndup(s, remain);
 	if ((*tag)->tagmsg == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strndup");
 		goto done;
 	}
 done:
@@ -899,7 +899,7 @@ got_read_file_to_mem(uint8_t **outbuf, size_t *outlen,
 
 	buf = malloc(blocksize);
 	if (buf == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 
 	remain = blocksize;
 	total = 0;
@@ -908,7 +908,7 @@ got_read_file_to_mem(uint8_t **outbuf, size_t *outlen,
 			uint8_t *newbuf;
 			newbuf = reallocarray(buf, 1, total + blocksize);
 			if (newbuf == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("reallocarray");
 				goto done;
 			}
 			buf = newbuf;
blob - b9667ec410d6319b83dcc489049007dd715f5889
blob + a57145d2b038aab6670b164672f242bdd3fc598e
--- lib/opentemp.c
+++ lib/opentemp.c
@@ -66,12 +66,12 @@ got_opentemp_named(char **path, FILE **outfile, const 
 
 	if (asprintf(path, "%s-XXXXXX", basepath) == -1) {
 		*path = NULL;
-		return got_error_from_errno();
+		return got_error_prefix_errno("asprintf");
 	}
 
 	fd = mkstemp(*path);
 	if (fd == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("mkstemp");
 		free(*path);
 		*path = NULL;
 		return err;
@@ -79,7 +79,7 @@ got_opentemp_named(char **path, FILE **outfile, const 
 
 	*outfile = fdopen(fd, "w+");
 	if (*outfile == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fdopen");
 		free(*path);
 		*path = NULL;
 	}
@@ -97,12 +97,12 @@ got_opentemp_named_fd(char **path, int *outfd, const c
 
 	if (asprintf(path, "%s-XXXXXX", basepath) == -1) {
 		*path = NULL;
-		return got_error_from_errno();
+		return got_error_prefix_errno("asprintf");
 	}
 
 	fd = mkstemp(*path);
 	if (fd == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("mkstemp");
 		free(*path);
 		*path = NULL;
 		return err;
blob - 11d1e5017d0a95ea7ae5ecf9df6bb025770e1f9d
blob + 8e7bca71c1527510b415e58c7e90e5c655811ca6
--- lib/pack.c
+++ lib/pack.c
@@ -91,16 +91,16 @@ got_pack_get_packfile_size(size_t *size, const char *p
 			return got_error(GOT_ERR_BAD_PATH);
 		*dot = '\0';
 		if (asprintf(&path_pack, "%s.pack", base_path) == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("asprintf");
 
 		if (stat(path_pack, &sb) != 0)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("asprintf");
 		free(path_pack);
 		if (err)
 			return err;
 	} else if (strcmp(dot, GOT_PACKFILE_SUFFIX) == 0) {
 		if (stat(path, &sb) != 0)
-			return got_error_from_errno();
+			return got_error_prefix_errno2("stat", path);
 	} else
 		return got_error(GOT_ERR_BAD_PATH);
 
@@ -133,12 +133,12 @@ got_packidx_init_hdr(struct got_packidx *p, int verify
 	else {
 		h->magic = malloc(sizeof(*h->magic));
 		if (h->magic == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("malloc");
 			goto done;
 		}
 		n = read(p->fd, h->magic, sizeof(*h->magic));
 		if (n < 0)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("read");
 		else if (n != sizeof(*h->magic)) {
 			err = got_error(GOT_ERR_BAD_PACKIDX);
 			goto done;
@@ -163,12 +163,12 @@ got_packidx_init_hdr(struct got_packidx *p, int verify
 	else {
 		h->version = malloc(sizeof(*h->version));
 		if (h->version == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("malloc");
 			goto done;
 		}
 		n = read(p->fd, h->version, sizeof(*h->version));
 		if (n < 0)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("read");
 		else if (n != sizeof(*h->version)) {
 			err = got_error(GOT_ERR_BAD_PACKIDX);
 			goto done;
@@ -195,12 +195,12 @@ got_packidx_init_hdr(struct got_packidx *p, int verify
 	else {
 		h->fanout_table = malloc(len_fanout);
 		if (h->fanout_table == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("malloc");
 			goto done;
 		}
 		n = read(p->fd, h->fanout_table, len_fanout);
 		if (n < 0)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("read");
 		else if (n != len_fanout) {
 			err = got_error(GOT_ERR_BAD_PACKIDX);
 			goto done;
@@ -231,7 +231,7 @@ got_packidx_init_hdr(struct got_packidx *p, int verify
 		}
 		n = read(p->fd, h->sorted_ids, len_ids);
 		if (n < 0)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("read");
 		else if (n != len_ids) {
 			err = got_error(GOT_ERR_BAD_PACKIDX);
 			goto done;
@@ -251,12 +251,12 @@ got_packidx_init_hdr(struct got_packidx *p, int verify
 	else {
 		h->crc32 = malloc(nobj * sizeof(*h->crc32));
 		if (h->crc32 == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("malloc");
 			goto done;
 		}
 		n = read(p->fd, h->crc32, nobj * sizeof(*h->crc32));
 		if (n < 0)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("read");
 		else if (n != nobj * sizeof(*h->crc32)) {
 			err = got_error(GOT_ERR_BAD_PACKIDX);
 			goto done;
@@ -276,12 +276,12 @@ got_packidx_init_hdr(struct got_packidx *p, int verify
 	else {
 		h->offsets = malloc(nobj * sizeof(*h->offsets));
 		if (h->offsets == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("malloc");
 			goto done;
 		}
 		n = read(p->fd, h->offsets, nobj * sizeof(*h->offsets));
 		if (n < 0)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("read");
 		else if (n != nobj * sizeof(*h->offsets)) {
 			err = got_error(GOT_ERR_BAD_PACKIDX);
 			goto done;
@@ -306,13 +306,13 @@ got_packidx_init_hdr(struct got_packidx *p, int verify
 	else {
 		h->offsets = malloc(nobj * sizeof(*h->large_offsets));
 		if (h->offsets == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("malloc");
 			goto done;
 		}
 		n = read(p->fd, h->large_offsets,
 		    nobj * sizeof(*h->large_offsets));
 		if (n < 0)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("read");
 		else if (n != nobj * sizeof(*h->large_offsets)) {
 			err = got_error(GOT_ERR_BAD_PACKIDX);
 			goto done;
@@ -335,12 +335,12 @@ checksum:
 	else {
 		h->trailer = malloc(sizeof(*h->trailer));
 		if (h->trailer == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("malloc");
 			goto done;
 		}
 		n = read(p->fd, h->trailer, sizeof(*h->trailer));
 		if (n < 0)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("read");
 		else if (n != sizeof(*h->trailer)) {
 			err = got_error(GOT_ERR_BAD_PACKIDX);
 			goto done;
@@ -367,11 +367,11 @@ got_packidx_open(struct got_packidx **packidx, const c
 
 	p = calloc(1, sizeof(*p));
 	if (p == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	p->fd = open(path, O_RDONLY | O_NOFOLLOW);
 	if (p->fd == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("open", path);
 
 	err = got_pack_get_packfile_size(&p->len, path);
 	if (err) {
@@ -388,7 +388,7 @@ got_packidx_open(struct got_packidx **packidx, const c
 
 	p->path_packidx = strdup(path);
 	if (p->path_packidx == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		goto done;
 	}
 
@@ -396,7 +396,7 @@ got_packidx_open(struct got_packidx **packidx, const c
 	p->map = mmap(NULL, p->len, PROT_READ, MAP_PRIVATE, p->fd, 0);
 	if (p->map == MAP_FAILED) {
 		if (errno != ENOMEM) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("mmap");
 			goto done;
 		}
 		p->map = NULL; /* fall back to read(2) */
@@ -421,7 +421,7 @@ got_packidx_close(struct got_packidx *packidx)
 	free(packidx->path_packidx);
 	if (packidx->map) {
 		if (munmap(packidx->map, packidx->len) == -1)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("munmap");
 	} else {
 		free(packidx->hdr.magic);
 		free(packidx->hdr.version);
@@ -433,7 +433,7 @@ got_packidx_close(struct got_packidx *packidx)
 		free(packidx->hdr.trailer);
 	}
 	if (close(packidx->fd) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	free(packidx);
 
 	return err;
@@ -497,7 +497,7 @@ got_pack_stop_privsep_child(struct got_pack *pack)
 		return err;
 	err = got_privsep_wait_for_child(pack->privsep_child->pid);
 	if (close(pack->privsep_child->imsg_fd) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	free(pack->privsep_child);
 	pack->privsep_child = NULL;
 	return err;
@@ -510,9 +510,9 @@ got_pack_close(struct got_pack *pack)
 
 	err = got_pack_stop_privsep_child(pack);
 	if (pack->map && munmap(pack->map, pack->filesize) == -1 && !err)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("munmap");
 	if (pack->fd != -1 && close(pack->fd) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	pack->fd = -1;
 	free(pack->path_packfile);
 	pack->path_packfile = NULL;
@@ -540,7 +540,7 @@ parse_object_type_and_size(uint8_t *type, uint64_t *si
 		mapoff = (size_t)offset;
 	} else {
 		if (lseek(pack->fd, offset, SEEK_SET) == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("lseek");
 	}
 
 	do {
@@ -554,7 +554,7 @@ parse_object_type_and_size(uint8_t *type, uint64_t *si
 		} else {
 			ssize_t n = read(pack->fd, &sizeN, sizeof(sizeN));
 			if (n < 0)
-				return got_error_from_errno();
+				return got_error_prefix_errno("read");
 			if (n != sizeof(sizeN))
 				return got_error(GOT_ERR_BAD_PACKFILE);
 		}
@@ -582,11 +582,11 @@ open_plain_object(struct got_object **obj, const char 
 {
 	*obj = calloc(1, sizeof(**obj));
 	if (*obj == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	(*obj)->path_packfile = strdup(path_packfile);
 	if ((*obj)->path_packfile == NULL) {
-		const struct got_error *err = got_error_from_errno();
+		const struct got_error *err = got_error_prefix_errno("strdup");
 		free(*obj);
 		*obj = NULL;
 		return err;
@@ -628,7 +628,7 @@ parse_negative_offset(int64_t *offset, size_t *len, st
 			ssize_t n;
 			n = read(pack->fd, &offN, sizeof(offN));
 			if (n < 0)
-				return got_error_from_errno();
+				return got_error_prefix_errno("read");
 			if (n != sizeof(offN))
 				return got_error(GOT_ERR_BAD_PACKFILE);
 		}
@@ -687,7 +687,7 @@ add_delta(struct got_delta_chain *deltas, off_t delta_
 	    delta_data_offset, delta_buf,
 	    delta_len);
 	if (delta == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("got_delta_open");
 	/* delta is freed in got_object_close() */
 	deltas->nentries++;
 	SIMPLEQ_INSERT_HEAD(&deltas->entries, delta, entry);
@@ -721,7 +721,7 @@ resolve_offset_delta(struct got_delta_chain *deltas,
 	if (pack->map == NULL) {
 		delta_data_offset = lseek(pack->fd, 0, SEEK_CUR);
 		if (delta_data_offset == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("lseek");
 	}
 
 	if (pack->map) {
@@ -786,10 +786,9 @@ resolve_ref_delta(struct got_delta_chain *deltas, stru
 	if (pack->map == NULL) {
 		delta_data_offset = lseek(pack->fd, 0, SEEK_CUR);
 		if (delta_data_offset == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("lseek");
 	}
 
-
 	if (pack->map) {
 		size_t mapoff = (size_t)delta_data_offset;
 		memcpy(&id, pack->map + mapoff, sizeof(id));
@@ -801,7 +800,7 @@ resolve_ref_delta(struct got_delta_chain *deltas, stru
 	} else {
 		ssize_t n = read(pack->fd, &id, sizeof(id));
 		if (n < 0)
-			return got_error_from_errno();
+			return got_error_prefix_errno("read");
 		if (n != sizeof(id))
 			return got_error(GOT_ERR_BAD_PACKFILE);
 		err = got_inflate_to_mem_fd(&delta_buf, &delta_len, pack->fd);
@@ -889,7 +888,7 @@ open_delta_object(struct got_object **obj, struct got_
 
 	*obj = calloc(1, sizeof(**obj));
 	if (*obj == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	(*obj)->flags = 0;
 	(*obj)->hdrlen = 0;
@@ -899,7 +898,7 @@ open_delta_object(struct got_object **obj, struct got_
 
 	(*obj)->path_packfile = strdup(pack->path_packfile);
 	if ((*obj)->path_packfile == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		goto done;
 	}
 	(*obj)->flags |= GOT_OBJ_FLAG_PACKED;
@@ -1027,7 +1026,7 @@ dump_delta_chain_to_file(size_t *result_size, struct g
 	if (max_size < GOT_DELTA_RESULT_SIZE_CACHED_MAX) {
 		accum_buf = malloc(max_size);
 		if (accum_buf == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno("malloc");
 		base_file = NULL;
 		accum_file = NULL;
 	}
@@ -1055,7 +1054,7 @@ dump_delta_chain_to_file(size_t *result_size, struct g
 			if (pack->map == NULL) {
 				if (lseek(pack->fd, delta_data_offset, SEEK_SET)
 				    == -1) {
-					err = got_error_from_errno();
+					err = got_error_prefix_errno("lseek");
 					goto done;
 				}
 			}
@@ -1115,7 +1114,8 @@ dump_delta_chain_to_file(size_t *result_size, struct g
 					uint8_t *p;
 					p = reallocarray(base_buf, 1, max_size);
 					if (p == NULL) {
-						err = got_error_from_errno();
+						err = got_error_prefix_errno(
+						    "reallocarray");
 						goto done;
 					}
 					base_buf = p;
@@ -1169,7 +1169,7 @@ dump_delta_chain_to_mem(uint8_t **outbuf, size_t *outl
 		return err;
 	accum_buf = malloc(max_size);
 	if (accum_buf == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 
 	/* Deltas are ordered in ascending order. */
 	SIMPLEQ_FOREACH(delta, &deltas->entries, entry) {
@@ -1198,7 +1198,7 @@ dump_delta_chain_to_mem(uint8_t **outbuf, size_t *outl
 			} else {
 				if (lseek(pack->fd, delta_data_offset, SEEK_SET)
 				    == -1) {
-					err = got_error_from_errno();
+					err = got_error_prefix_errno("lseek");
 					goto done;
 				}
 				err = got_inflate_to_mem_fd(&base_buf,
@@ -1229,7 +1229,8 @@ dump_delta_chain_to_mem(uint8_t **outbuf, size_t *outl
 				uint8_t *p;
 				p = reallocarray(base_buf, 1, max_size);
 				if (p == NULL) {
-					err = got_error_from_errno();
+					err = got_error_prefix_errno(
+					    "reallocarray");
 					goto done;
 				}
 				base_buf = p;
@@ -1272,7 +1273,7 @@ got_packfile_extract_object(struct got_pack *pack, str
 			    mapoff, pack->filesize - mapoff, outfile);
 		} else {
 			if (lseek(pack->fd, obj->pack_offset, SEEK_SET) == -1)
-				return got_error_from_errno();
+				return got_error_prefix_errno("lseek");
 			err = got_inflate_to_file_fd(&obj->size, pack->fd,
 			    outfile);
 		}
@@ -1301,7 +1302,7 @@ got_packfile_extract_object_to_mem(uint8_t **buf, size
 			    mapoff, pack->filesize - mapoff);
 		} else {
 			if (lseek(pack->fd, obj->pack_offset, SEEK_SET) == -1)
-				return got_error_from_errno();
+				return got_error_prefix_errno("lseek");
 			err = got_inflate_to_mem_fd(buf, len, pack->fd);
 		}
 	} else
blob - 4c0f56363007cb794f3b12bdfadd5d1184d2e25a
blob + 3cbf1e571016182b989eabf6e95c60e0879b0314
--- lib/path.c
+++ lib/path.c
@@ -136,9 +136,9 @@ got_path_skip_common_ancestor(char **child, const char
 	bufsize = len - len_parent + 1;
 	*child = malloc(bufsize);
 	if (*child == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 	if (strlcpy(*child, abspath + len_parent, bufsize) >= bufsize) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strlcpy");
 		free(*child);
 		*child = NULL;
 		return err;
@@ -235,7 +235,7 @@ got_pathlist_insert(struct got_pathlist_entry **insert
 
 	new = malloc(sizeof(*new));
 	if (new == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 	new->path = path;
 	new->data = data;
 
@@ -294,11 +294,11 @@ make_parent_dirs(const char *abspath)
 			if (err)
 				goto done;
 			if (mkdir(parent, GOT_DEFAULT_DIR_MODE) == -1) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno2("mkdir", parent);
 				goto done;
 			}
 		} else
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("mkdir", parent);
 	}
 done:
 	free(parent);
@@ -316,9 +316,9 @@ got_path_mkdir(const char *abspath)
 			if (err)
 				goto done;
 			if (mkdir(abspath, GOT_DEFAULT_DIR_MODE) == -1)
-				err = got_error_from_errno();
+				err = got_error_prefix_errno2("mkdir", abspath);
 		} else
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("mkdir", abspath);
 	}
 
 done:
@@ -332,14 +332,14 @@ got_path_dirname(char **parent, const char *path)
 
 	p = dirname(path);
 	if (p == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("dirname", path);
 
 	if (p[0] == '.' && p[1] == '\0')
 		return got_error(GOT_ERR_BAD_PATH);
 
 	*parent = strdup(p);
 	if (*parent == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("strdup");
 
 	return NULL;
 }
blob - 1dd388018dac2f2a4e0f290a8a60976d4140796e
blob + b138fdd109686a0d479044350498422491478c1b
--- lib/privsep.c
+++ lib/privsep.c
@@ -57,11 +57,11 @@ poll_fd(int fd, int events, int timeout)
 
 	n = poll(pfd, 1, timeout);
 	if (n == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("poll");
 	if (n == 0)
 		return got_error(GOT_ERR_TIMEOUT);
 	if (pfd[0].revents & (POLLERR | POLLNVAL))
-		return got_error_from_errno();
+		return got_error_prefix_errno("poll error");
 	if (pfd[0].revents & (events | POLLHUP))
 		return NULL;
 
@@ -96,7 +96,7 @@ got_privsep_wait_for_child(pid_t pid)
 	int child_status;
 
 	if (waitpid(pid, &child_status, 0) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("waitpid");
 
 	if (!WIFEXITED(child_status))
 		return got_error(GOT_ERR_PRIVSEP_DIED);
@@ -135,7 +135,7 @@ got_privsep_recv_imsg(struct imsg *imsg, struct imsgbu
 
 	n = imsg_get(ibuf, imsg);
 	if (n == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("imsg_get");
 
 	while (n == 0) {
 		err = read_imsg(ibuf);
@@ -200,7 +200,7 @@ flush_imsg(struct imsgbuf *ibuf)
 		return err;
 
 	if (imsg_flush(ibuf) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("imsg_flush");
 
 	return NULL;
 }
@@ -214,7 +214,7 @@ got_privsep_send_stop(int fd)
 	imsg_init(&ibuf, fd);
 
 	if (imsg_compose(&ibuf, GOT_IMSG_STOP, 0, 0, -1, NULL, 0) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("imsg_compose STOP");
 
 	err = flush_imsg(&ibuf);
 	imsg_clear(&ibuf);
@@ -226,7 +226,7 @@ got_privsep_send_obj_req(struct imsgbuf *ibuf, int fd)
 {
 	if (imsg_compose(ibuf, GOT_IMSG_OBJECT_REQUEST, 0, 0, fd, NULL, 0)
 	    == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("imsg_compose OBJECT_REQUEST");
 
 	return flush_imsg(ibuf);
 }
@@ -251,7 +251,7 @@ got_privsep_send_commit_req(struct imsgbuf *ibuf, int 
 
 	if (imsg_compose(ibuf, GOT_IMSG_COMMIT_REQUEST, 0, 0, fd, iobjp, len)
 	    == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("imsg_compose COMMIT_REQUEST");
 		close(fd);
 		return err;
 	}
@@ -279,7 +279,7 @@ got_privsep_send_tree_req(struct imsgbuf *ibuf, int fd
 
 	if (imsg_compose(ibuf, GOT_IMSG_TREE_REQUEST, 0, 0, fd, iobjp, len)
 	    == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("imsg_compose TREE_REQUEST");
 		close(fd);
 		return err;
 	}
@@ -306,7 +306,7 @@ got_privsep_send_tag_req(struct imsgbuf *ibuf, int fd,
 
 	if (imsg_compose(ibuf, GOT_IMSG_TAG_REQUEST, 0, 0, fd, iobjp, len)
 	    == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("imsg_compose TAG_REQUEST");
 
 	return flush_imsg(ibuf);
 }
@@ -331,7 +331,7 @@ got_privsep_send_blob_req(struct imsgbuf *ibuf, int in
 
 	if (imsg_compose(ibuf, GOT_IMSG_BLOB_REQUEST, 0, 0, infd, iobjp, len)
 	    == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("imsg_compose BLOB_REQUEST");
 		close(infd);
 		return err;
 	}
@@ -346,7 +346,7 @@ got_privsep_send_blob_outfd(struct imsgbuf *ibuf, int 
 
 	if (imsg_compose(ibuf, GOT_IMSG_BLOB_OUTFD, 0, 0, outfd, NULL, 0)
 	    == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("imsg_compose BLOB_OUTFD");
 		close(outfd);
 		return err;
 	}
@@ -361,7 +361,7 @@ got_privsep_send_tmpfd(struct imsgbuf *ibuf, int fd)
 
 	if (imsg_compose(ibuf, GOT_IMSG_TMPFD, 0, 0, fd, NULL, 0)
 	    == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("imsg_compose TMPFD");
 		close(fd);
 		return err;
 	}
@@ -386,7 +386,7 @@ got_privsep_send_obj(struct imsgbuf *ibuf, struct got_
 
 	if (imsg_compose(ibuf, GOT_IMSG_OBJECT, 0, 0, -1, &iobj, sizeof(iobj))
 	    == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("imsg_compose OBJECT");
 
 	return flush_imsg(ibuf);
 }
@@ -405,7 +405,7 @@ got_privsep_get_imsg_obj(struct got_object **obj, stru
 
 	*obj = calloc(1, sizeof(**obj));
 	if (*obj == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	memcpy((*obj)->id.sha1, iobj->id, SHA1_DIGEST_LENGTH);
 	(*obj)->type = iobj->type;
@@ -466,7 +466,8 @@ send_commit_logmsg(struct imsgbuf *ibuf, struct got_co
 
 		if (imsg_compose(ibuf, GOT_IMSG_COMMIT_LOGMSG, 0, 0, -1,
 		    commit->logmsg + offset, n) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("imsg_compose "
+			    "COMMIT_LOGMSG");
 			break;
 		}
 
@@ -498,7 +499,7 @@ got_privsep_send_commit(struct imsgbuf *ibuf, struct g
 
 	buf = malloc(total);
 	if (buf == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 
 	icommit = (struct got_imsg_commit_object *)buf;
 	memcpy(icommit->tree_id, commit->tree_id->sha1,
@@ -523,7 +524,7 @@ got_privsep_send_commit(struct imsgbuf *ibuf, struct g
 	}
 
 	if (imsg_compose(ibuf, GOT_IMSG_COMMIT, 0, 0, -1, buf, len) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("imsg_compose COMMIT");
 		goto done;
 	}
 
@@ -581,7 +582,8 @@ got_privsep_recv_commit(struct got_commit_object **com
 
 		*commit = got_object_commit_alloc_partial();
 		if (*commit == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno(
+			    "got_object_commit_alloc_partial");
 			break;
 		}
 
@@ -595,13 +597,13 @@ got_privsep_recv_commit(struct got_commit_object **com
 		if (icommit->author_len == 0) {
 			(*commit)->author = strdup("");
 			if ((*commit)->author == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("strdup");
 				break;
 			}
 		} else {
 			(*commit)->author = malloc(icommit->author_len + 1);
 			if ((*commit)->author == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("malloc");
 				break;
 			}
 			memcpy((*commit)->author, imsg.data + len,
@@ -613,14 +615,14 @@ got_privsep_recv_commit(struct got_commit_object **com
 		if (icommit->committer_len == 0) {
 			(*commit)->committer = strdup("");
 			if ((*commit)->committer == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("strdup");
 				break;
 			}
 		} else {
 			(*commit)->committer =
 			    malloc(icommit->committer_len + 1);
 			if ((*commit)->committer == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("malloc");
 				break;
 			}
 			memcpy((*commit)->committer, imsg.data + len,
@@ -632,7 +634,7 @@ got_privsep_recv_commit(struct got_commit_object **com
 		if (icommit->logmsg_len == 0) {
 			(*commit)->logmsg = strdup("");
 			if ((*commit)->logmsg == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("strdup");
 				break;
 			}
 		} else {
@@ -640,7 +642,7 @@ got_privsep_recv_commit(struct got_commit_object **com
 
 			(*commit)->logmsg = malloc(icommit->logmsg_len + 1);
 			if ((*commit)->logmsg == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("malloc");
 				break;
 			}
 			while (remain > 0) {
@@ -698,7 +700,7 @@ got_privsep_send_tree(struct imsgbuf *ibuf, struct got
 	itree.nentries = tree->entries.nentries;
 	if (imsg_compose(ibuf, GOT_IMSG_TREE, 0, 0, -1, &itree, sizeof(itree))
 	    == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("imsg_compose TREE");
 
 	totlen = sizeof(itree);
 	nimsg = 1;
@@ -720,7 +722,7 @@ got_privsep_send_tree(struct imsgbuf *ibuf, struct got
 
 		buf = malloc(len);
 		if (buf == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno("malloc");
 
 		ite = (struct got_imsg_tree_entry *)buf;
 		memcpy(ite->id, te->id->sha1, sizeof(ite->id));
@@ -729,7 +731,7 @@ got_privsep_send_tree(struct imsgbuf *ibuf, struct got
 
 		if (imsg_compose(ibuf, GOT_IMSG_TREE_ENTRY, 0, 0, -1,
 		    buf, len) == -1)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("imsg_compose TREE_ENTRY");
 		free(buf);
 		if (err)
 			return err;
@@ -791,7 +793,7 @@ get_more:
 			itree = imsg.data;
 			*tree = malloc(sizeof(**tree));
 			if (*tree == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("malloc");
 				break;
 			}
 			(*tree)->entries.nentries = itree->nentries;
@@ -819,13 +821,14 @@ get_more:
 
 			te = got_alloc_tree_entry_partial();
 			if (te == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno(
+				    "got_alloc_tree_entry_partial");
 				break;
 			}
 			te->name = malloc(datalen + 1);
 			if (te->name == NULL) {
 				free(te);
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("malloc");
 				break;
 			}
 			memcpy(te->name, imsg.data + sizeof(*ite), datalen);
@@ -871,21 +874,21 @@ got_privsep_send_blob(struct imsgbuf *ibuf, size_t siz
 
 		buf = malloc(sizeof(iblob) + size);
 		if (buf == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno("malloc");
 
 		memcpy(buf, &iblob, sizeof(iblob));
 		memcpy(buf + sizeof(iblob), data, size);
 		if (imsg_compose(ibuf, GOT_IMSG_BLOB, 0, 0, -1, buf,
 		   sizeof(iblob) + size) == -1) {
 			free(buf);
-			return got_error_from_errno();
+			return got_error_prefix_errno("imsg_compose BLOB");
 		}
 		free(buf);
 	} else {
 		/* Data has already been written to file descriptor. */
 		if (imsg_compose(ibuf, GOT_IMSG_BLOB, 0, 0, -1, &iblob,
 		    sizeof(iblob)) == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("imsg_compose BLOB");
 	}
 
 
@@ -931,7 +934,7 @@ got_privsep_recv_blob(uint8_t **outbuf, size_t *size, 
 
 		*outbuf = malloc(*size);
 		if (*outbuf == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("malloc");
 			break;
 		}
 		memcpy(*outbuf, imsg.data + sizeof(*iblob), *size);
@@ -959,7 +962,7 @@ send_tagmsg(struct imsgbuf *ibuf, struct got_tag_objec
 
 		if (imsg_compose(ibuf, GOT_IMSG_TAG_TAGMSG, 0, 0, -1,
 		    tag->tagmsg + offset, n) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("imsg_compose TAG_TAGMSG");
 			break;
 		}
 
@@ -989,7 +992,7 @@ got_privsep_send_tag(struct imsgbuf *ibuf, struct got_
 
 	buf = malloc(total);
 	if (buf == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 
 	itag = (struct got_imsg_tag_object *)buf;
 	memcpy(itag->id, tag->id.sha1, sizeof(itag->id));
@@ -1007,7 +1010,7 @@ got_privsep_send_tag(struct imsgbuf *ibuf, struct got_
 	len += tagger_len;
 
 	if (imsg_compose(ibuf, GOT_IMSG_TAG, 0, 0, -1, buf, len) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("imsg_compose TAG");
 		goto done;
 	}
 
@@ -1059,7 +1062,7 @@ got_privsep_recv_tag(struct got_tag_object **tag, stru
 
 		*tag = calloc(1, sizeof(**tag));
 		if (*tag == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("calloc");
 			break;
 		}
 
@@ -1068,13 +1071,13 @@ got_privsep_recv_tag(struct got_tag_object **tag, stru
 		if (itag->tag_len == 0) {
 			(*tag)->tag = strdup("");
 			if ((*tag)->tag == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("strdup");
 				break;
 			}
 		} else {
 			(*tag)->tag = malloc(itag->tag_len + 1);
 			if ((*tag)->tag == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("malloc");
 				break;
 			}
 			memcpy((*tag)->tag, imsg.data + len,
@@ -1090,13 +1093,13 @@ got_privsep_recv_tag(struct got_tag_object **tag, stru
 		if (itag->tagger_len == 0) {
 			(*tag)->tagger = strdup("");
 			if ((*tag)->tagger == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("strdup");
 				break;
 			}
 		} else {
 			(*tag)->tagger = malloc(itag->tagger_len + 1);
 			if ((*tag)->tagger == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("malloc");
 				break;
 			}
 			memcpy((*tag)->tagger, imsg.data + len,
@@ -1108,7 +1111,7 @@ got_privsep_recv_tag(struct got_tag_object **tag, stru
 		if (itag->tagmsg_len == 0) {
 			(*tag)->tagmsg = strdup("");
 			if ((*tag)->tagmsg == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("strdup");
 				break;
 			}
 		} else {
@@ -1116,7 +1119,7 @@ got_privsep_recv_tag(struct got_tag_object **tag, stru
 
 			(*tag)->tagmsg = malloc(itag->tagmsg_len + 1);
 			if ((*tag)->tagmsg == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("malloc");
 				break;
 			}
 			while (remain > 0) {
@@ -1163,11 +1166,11 @@ got_privsep_init_pack_child(struct imsgbuf *ibuf, stru
 	ipackidx.len = packidx->len;
 	fd = dup(packidx->fd);
 	if (fd == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("dup");
 
 	if (imsg_compose(ibuf, GOT_IMSG_PACKIDX, 0, 0, fd, &ipackidx,
 	    sizeof(ipackidx)) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("imsg_compose PACKIDX");
 		close(fd);
 		return err;
 	}
@@ -1179,11 +1182,11 @@ got_privsep_init_pack_child(struct imsgbuf *ibuf, stru
 
 	fd = dup(pack->fd);
 	if (fd == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("dup");
 
 	if (imsg_compose(ibuf, GOT_IMSG_PACK, 0, 0, fd, &ipack, sizeof(ipack))
 	    == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("imsg_compose PACK");
 		close(fd);
 		return err;
 	}
@@ -1202,7 +1205,8 @@ got_privsep_send_packed_obj_req(struct imsgbuf *ibuf, 
 
 	if (imsg_compose(ibuf, GOT_IMSG_PACKED_OBJECT_REQUEST, 0, 0, -1,
 	    &iobj, sizeof(iobj)) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("imsg_compose "
+		    "PACKED_OBJECT_REQUEST");
 
 	return flush_imsg(ibuf);
 }
@@ -1216,7 +1220,7 @@ got_privsep_unveil_exec_helpers(void)
 	    unveil(GOT_PATH_PROG_READ_TREE, "x") != 0 ||
 	    unveil(GOT_PATH_PROG_READ_BLOB, "x") != 0 ||
 	    unveil(GOT_PATH_PROG_READ_TAG, "x") != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("unveil");
 
 	return NULL;
 }
blob - a33e604ced7ec4e337f571bc9f44ca9de3bbd8fb
blob + 71cd05412075b820ffecc78e142ec85d5c895b2f
--- lib/reference.c
+++ lib/reference.c
@@ -90,13 +90,13 @@ alloc_ref(struct got_reference **ref, const char *name
 
 	*ref = calloc(1, sizeof(**ref));
 	if (*ref == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	memcpy((*ref)->ref.ref.sha1, id->sha1, sizeof((*ref)->ref.ref.sha1));
 	(*ref)->flags = flags;
 	(*ref)->ref.ref.name = strdup(name);
 	if ((*ref)->ref.ref.name == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		got_ref_close(*ref);
 		*ref = NULL;
 	}
@@ -111,18 +111,18 @@ alloc_symref(struct got_reference **ref, const char *n
 
 	*ref = calloc(1, sizeof(**ref));
 	if (*ref == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	(*ref)->flags = GOT_REF_IS_SYMBOLIC | flags;
 	(*ref)->ref.symref.name = strdup(name);
 	if ((*ref)->ref.symref.name == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		got_ref_close(*ref);
 		*ref = NULL;
 	}
 	(*ref)->ref.symref.ref = strdup(target_ref);
 	if ((*ref)->ref.symref.ref == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		got_ref_close(*ref);
 		*ref = NULL;
 	}
@@ -178,7 +178,7 @@ parse_ref_file(struct got_reference **ref, const char 
 done:
 	free(line);
 	if (fclose(f) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	return err;
 }
 
@@ -317,7 +317,7 @@ open_packed_ref(struct got_reference **ref, FILE *f, c
 			if (!ref_is_absolute &&
 			    asprintf(&abs_refname, "refs/%s/%s", subdirs[i],
 			    refname) == -1)
-				return got_error_from_errno();
+				return got_error_prefix_errno("asprintf");
 			err = parse_packed_ref_line(ref, abs_refname, line);
 			if (!ref_is_absolute)
 				free(abs_refname);
@@ -347,23 +347,23 @@ open_ref(struct got_reference **ref, const char *path_
 
 	if (ref_is_absolute || ref_is_well_known) {
 		if (asprintf(&path, "%s/%s", path_refs, name) == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("asprintf");
 		absname = (char *)name;
 	} else {
 		if (asprintf(&path, "%s/%s%s%s", path_refs, subdir,
 		    subdir[0] ? "/" : "", name) == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("asprintf");
 
 		if (asprintf(&absname, "refs/%s%s%s",
 		    subdir, subdir[0] ? "/" : "", name) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("asprintf");
 			goto done;
 		}
 	}
 
 	normpath = got_path_normalize(path);
 	if (normpath == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("got_path_normalize", path);
 		goto done;
 	}
 
@@ -391,7 +391,7 @@ got_ref_open(struct got_reference **ref, struct got_re
 
 	path_refs = get_refs_dir_path(repo, refname);
 	if (path_refs == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("get_refs_dir_path", refname);
 		goto done;
 	}
 
@@ -408,7 +408,8 @@ got_ref_open(struct got_reference **ref, struct got_re
 
 		packed_refs_path = got_repo_get_path_packed_refs(repo);
 		if (packed_refs_path == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno(
+			    "got_repo_get_path_packed_refs");
 			goto done;
 		}
 
@@ -418,7 +419,7 @@ got_ref_open(struct got_reference **ref, struct got_re
 			err = open_packed_ref(ref, f, subdirs, nitems(subdirs),
 			    refname);
 			if (fclose(f) != 0 && err == NULL)
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("fclose");
 			if (err || *ref)
 				goto done;
 		}
@@ -518,7 +519,7 @@ got_ref_resolve(struct got_object_id **id, struct got_
 
 	*id = calloc(1, sizeof(**id));
 	if (*id == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 	memcpy((*id)->sha1, ref->ref.ref.sha1, sizeof((*id)->sha1));
 	return NULL;
 }
@@ -571,7 +572,7 @@ insert_ref(struct got_reflist_entry **newp, struct got
 	new = malloc(sizeof(*new));
 	if (new == NULL) {
 		free(id);
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 	}
 	new->ref = ref;
 	new->id = id;
@@ -618,7 +619,7 @@ gather_on_disk_refs(struct got_reflist_head *refs, con
 	char *path_subdir;
 
 	if (asprintf(&path_subdir, "%s/%s", path_refs, subdir) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("asprintf");
 
 	d = opendir(path_subdir);
 	if (d == NULL)
@@ -654,7 +655,7 @@ gather_on_disk_refs(struct got_reflist_head *refs, con
 		case DT_DIR:
 			if (asprintf(&child, "%s%s%s", subdir,
 			    subdir[0] == '\0' ? "" : "/", dent->d_name) == -1) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("asprintf");
 				break;
 			}
 			err = gather_on_disk_refs(refs, path_refs, child, repo);
@@ -683,7 +684,7 @@ got_ref_list(struct got_reflist_head *refs, struct got
 	/* HEAD ref should always exist. */
 	path_refs = get_refs_dir_path(repo, GOT_REF_HEAD);
 	if (path_refs == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("get_refs_dir_path");
 		goto done;
 	}
 	err = open_ref(&ref, path_refs, "", GOT_REF_HEAD);
@@ -699,7 +700,7 @@ got_ref_list(struct got_reflist_head *refs, struct got
 	free(path_refs);
 	path_refs = get_refs_dir_path(repo, "");
 	if (path_refs == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("get_refs_dir_path");
 		goto done;
 	}
 	err = gather_on_disk_refs(refs, path_refs, "", repo);
@@ -712,7 +713,7 @@ got_ref_list(struct got_reflist_head *refs, struct got
 	 */
 	packed_refs_path = got_repo_get_path_packed_refs(repo);
 	if (packed_refs_path == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_repo_get_path_packed_refs");
 		goto done;
 	}
 
@@ -746,7 +747,7 @@ got_ref_list(struct got_reflist_head *refs, struct got
 done:
 	free(path_refs);
 	if (f && fclose(f) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	return err;
 }
 
@@ -791,7 +792,7 @@ got_ref_change_symref(struct got_reference *ref, char 
 
 	new_name = strdup(refname);
 	if (new_name == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("strdup");
 
 	free(ref->ref.symref.name);
 	ref->ref.symref.name = new_name;
@@ -811,12 +812,12 @@ got_ref_write(struct got_reference *ref, struct got_re
 
 	path_refs = get_refs_dir_path(repo, name);
 	if (path_refs == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("get_refs_dir_path", name);
 		goto done;
 	}
 
 	if (asprintf(&path, "%s/%s", path_refs, name) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 
@@ -865,21 +866,21 @@ got_ref_write(struct got_reference *ref, struct got_re
 
 	if (stat(path, &sb) != 0) {
 		if (errno != ENOENT) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("stat", path);
 			goto done;
 		}
 		sb.st_mode = GOT_DEFAULT_FILE_MODE;
 	}
 
 	if (rename(tmppath, path) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno3("rename", tmppath, path);
 		goto done;
 	}
 	free(tmppath);
 	tmppath = NULL;
 
 	if (chmod(path, sb.st_mode) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("chmod", path);
 		goto done;
 	}
 done:
@@ -887,13 +888,13 @@ done:
 		unlock_err = got_lockfile_unlock(lf);
 	if (f) {
 		if (fclose(f) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fclose");
 	}
 	free(path_refs);
 	free(path);
 	if (tmppath) {
 		if (unlink(tmppath) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("unlink", tmppath);
 		free(tmppath);
 	}
 	return err ? err : unlock_err;
@@ -917,7 +918,7 @@ delete_packed_ref(struct got_reference *delref, struct
 
 	packed_refs_path = got_repo_get_path_packed_refs(repo);
 	if (packed_refs_path == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("got_repo_get_path_packed_refs");
 
 	err = got_opentemp_named(&tmppath, &tmpf, packed_refs_path);
 	if (err)
@@ -929,7 +930,7 @@ delete_packed_ref(struct got_reference *delref, struct
 
 	f = fopen(packed_refs_path, "r");
 	if (f == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("fopen", packed_refs_path);
 		goto done;
 	}
 	while (1) {
@@ -1000,25 +1001,28 @@ delete_packed_ref(struct got_reference *delref, struct
 		}
 
 		if (fflush(tmpf) != 0) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fflush");
 			goto done;
 		}
 
 		if (stat(packed_refs_path, &sb) != 0) {
 			if (errno != ENOENT) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno2("stat",
+				    packed_refs_path);
 				goto done;
 			}
 			sb.st_mode = GOT_DEFAULT_FILE_MODE;
 		}
 
 		if (rename(tmppath, packed_refs_path) != 0) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno3("rename", tmppath,
+			    packed_refs_path);
 			goto done;
 		}
 
 		if (chmod(packed_refs_path, sb.st_mode) != 0) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("chmod",
+			    packed_refs_path);
 			goto done;
 		}
 	}
@@ -1027,12 +1031,12 @@ done:
 		unlock_err = got_lockfile_unlock(lf);
 	if (f) {
 		if (fclose(f) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fclose");
 	}
 	if (tmpf) {
 		unlink(tmppath);
 		if (fclose(tmpf) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fclose");
 	}
 	free(tmppath);
 	free(packed_refs_path);
@@ -1053,12 +1057,12 @@ got_ref_delete(struct got_reference *ref, struct got_r
 
 	path_refs = get_refs_dir_path(repo, name);
 	if (path_refs == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("get_refs_dir_path", name);
 		goto done;
 	}
 
 	if (asprintf(&path, "%s/%s", path_refs, name) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 
@@ -1069,7 +1073,7 @@ got_ref_delete(struct got_reference *ref, struct got_r
 	/* XXX: check if old content matches our expectations? */
 
 	if (unlink(path) != 0)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("unlink", path);
 done:
 	if (lf)
 		unlock_err = got_lockfile_unlock(lf);
blob - 97763ccc4a03b11ad76e0aa9dd7083d2b46c387f
blob + 51cd9ab428652c5c6affa2a392e422b3f039339a
--- lib/repository.c
+++ lib/repository.c
@@ -267,11 +267,11 @@ open_repo(struct got_repository *repo, const char *pat
 	/* bare git repository? */
 	repo->path_git_dir = strdup(path);
 	if (repo->path_git_dir == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("strdup");
 	if (is_git_repo(repo)) {
 		repo->path = strdup(repo->path_git_dir);
 		if (repo->path == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("strdup");
 			goto done;
 		}
 		return NULL;
@@ -280,13 +280,13 @@ open_repo(struct got_repository *repo, const char *pat
 	/* git repository with working tree? */
 	free(repo->path_git_dir);
 	if (asprintf(&repo->path_git_dir, "%s/%s", path, GOT_GIT_DIR) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 	if (is_git_repo(repo)) {
 		repo->path = strdup(path);
 		if (repo->path == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("strdup");
 			goto done;
 		}
 		return NULL;
@@ -322,7 +322,7 @@ got_repo_open(struct got_repository **repop, const cha
 
 	repo = calloc(1, sizeof(*repo));
 	if (repo == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("calloc");
 		goto done;
 	}
 
@@ -371,7 +371,7 @@ got_repo_open(struct got_repository **repop, const cha
 		}
 		path = dirname(path);
 		if (path == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("dirname", path);
 	} while (path);
 done:
 	if (err)
@@ -421,7 +421,7 @@ got_repo_close(struct got_repository *repo)
 			err = child_err;
 		if (close(repo->privsep_children[i].imsg_fd) != 0 &&
 		    err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("close");
 	}
 	free(repo);
 
@@ -441,11 +441,11 @@ got_repo_map_path(char **in_repo_path, struct got_repo
 
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("getcwd");
 
 	canonpath = strdup(input_path);
 	if (canonpath == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		goto done;
 	}
 	err = got_canonpath(input_path, canonpath, strlen(canonpath) + 1);
@@ -457,7 +457,7 @@ got_repo_map_path(char **in_repo_path, struct got_repo
 	if (!check_disk) {
 		path = strdup(canonpath);
 		if (path == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("strdup");
 			goto done;
 		}
 	} else {
@@ -466,7 +466,8 @@ got_repo_map_path(char **in_repo_path, struct got_repo
 		path = realpath(canonpath, NULL);
 		if (path == NULL) {
 			if (errno != ENOENT) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno2("realpath",
+				    canonpath);
 				goto done;
 			}
 			/*
@@ -475,7 +476,7 @@ got_repo_map_path(char **in_repo_path, struct got_repo
 			 */
 			path = strdup(canonpath);
 			if (path == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("strdup");
 				goto done;
 			}
 		}
@@ -493,7 +494,7 @@ got_repo_map_path(char **in_repo_path, struct got_repo
 			free(path);
 			path = strdup("");
 			if (path == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("strdup");
 				goto done;
 			}
 		} else if (is_repo_child && is_cwd_child) {
@@ -543,7 +544,7 @@ got_repo_map_path(char **in_repo_path, struct got_repo
 	if (path[0] != '/') {
 		char *abspath;
 		if (asprintf(&abspath, "/%s", path) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("asprintf");
 			goto done;
 		}
 		free(path);
@@ -629,11 +630,11 @@ got_repo_search_packidx(struct got_packidx **packidx, 
 
 	path_packdir = got_repo_get_path_objects_pack(repo);
 	if (path_packdir == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("got_repo_get_path_objects_pack");
 
 	packdir = opendir(path_packdir);
 	if (packdir == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("opendir", path_packdir);
 		goto done;
 	}
 
@@ -643,7 +644,7 @@ got_repo_search_packidx(struct got_packidx **packidx, 
 
 		if (asprintf(&path_packidx, "%s/%s", path_packdir,
 		    dent->d_name) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("asprintf");
 			goto done;
 		}
 
@@ -669,7 +670,7 @@ got_repo_search_packidx(struct got_packidx **packidx, 
 done:
 	free(path_packdir);
 	if (packdir && closedir(packdir) != 0 && err == 0)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("closedir");
 	return err;
 }
 
@@ -683,7 +684,7 @@ read_packfile_hdr(int fd, struct got_packidx *packidx)
 
 	n = read(fd, &hdr, sizeof(hdr));
 	if (n < 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("read");
 	if (n != sizeof(hdr))
 		return got_error(GOT_ERR_BAD_PACKFILE);
 
@@ -702,7 +703,7 @@ open_packfile(int *fd, const char *path_packfile, stru
 
 	*fd = open(path_packfile, O_RDONLY | O_NOFOLLOW);
 	if (*fd == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("open", path_packfile);
 
 	if (packidx) {
 		err = read_packfile_hdr(*fd, packidx);
@@ -747,7 +748,7 @@ got_repo_cache_pack(struct got_pack **packp, struct go
 
 	pack->path_packfile = strdup(path_packfile);
 	if (pack->path_packfile == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		goto done;
 	}
 
@@ -766,7 +767,7 @@ got_repo_cache_pack(struct got_pack **packp, struct go
 	    pack->fd, 0);
 	if (pack->map == MAP_FAILED) {
 		if (errno != ENOMEM) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("mmap");
 			goto done;
 		}
 		pack->map = NULL; /* fall back to read(2) */
blob - f1d5f2fac1be26bb13465eb2a3b837c311a29b4f
blob + 53fc4a5db64d58550cdf558c5f45e93be6eaf848
--- lib/utf8.c
+++ lib/utf8.c
@@ -36,7 +36,7 @@ got_mbsavis(char** outp, int *widthp, const char *mbs)
 
 	len = strlen(mbs);
 	if ((*outp = malloc(len + 1)) == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("malloc");
 
 	if (MB_CUR_MAX == 1) {
 		memcpy(*outp, mbs, len + 1);
blob - 76ce96aa12df9c6519f2f358e39234f59bb9be64
blob + 9186607062c7b5c859c727a75daad76225a91a48
--- lib/worklist.c
+++ lib/worklist.c
@@ -48,7 +48,7 @@ worklist_add(const char *path, struct wklhead *worklis
 
 	wkl = calloc(1, sizeof(*wkl));
 	if (wkl == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	len = strlcpy(wkl->wkl_path, path, sizeof(wkl->wkl_path));
 	if (len >= sizeof(wkl->wkl_path))
blob - 4f7289e40f1cc7cb018515aeb36977371856a3b0
blob + 3aab97147502fae16a1bb23ec3bcf5de9577a7cc
--- lib/worktree.c
+++ lib/worktree.c
@@ -73,21 +73,21 @@ create_meta_file(const char *path_got, const char *nam
 	fd = open(path, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW,
 	    GOT_DEFAULT_FILE_MODE);
 	if (fd == -1) {
-		err = got_error_prefix_errno(path);
+		err = got_error_prefix_errno2("open", path);
 		goto done;
 	}
 
 	if (content) {
 		int len = dprintf(fd, "%s\n", content);
 		if (len != strlen(content) + 1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("dprintf");
 			goto done;
 		}
 	}
 
 done:
 	if (fd != -1 && close(fd) == -1 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	free(path);
 	return err;
 }
@@ -113,21 +113,21 @@ update_meta_file(const char *path_got, const char *nam
 	if (content) {
 		int len = fprintf(tmpfile, "%s\n", content);
 		if (len != strlen(content) + 1) {
-			err = got_error_prefix_errno(tmppath);
+			err = got_error_prefix_errno2("fprintf", tmppath);
 			goto done;
 		}
 	}
 
 	if (rename(tmppath, path) != 0) {
-		err = got_error_prefix_errno(tmppath);
+		err = got_error_prefix_errno3("rename", tmppath, path);
 		unlink(tmppath);
 		goto done;
 	}
 
 done:
-	free(tmppath);
 	if (fclose(tmpfile) != 0 && err == NULL)
-		err = got_error_prefix_errno("fclose");
+		err = got_error_prefix_errno2("fclose", tmppath);
+	free(tmppath);
 	return err;
 }
 
@@ -153,17 +153,17 @@ read_meta_file(char **content, const char *path_got, c
 		if (errno == ENOENT)
 			err = got_error(GOT_ERR_WORKTREE_META);
 		else
-			err = got_error_prefix_errno(path);
+			err = got_error_prefix_errno2("open", path);
 		goto done;
 	}
 	if (flock(fd, LOCK_SH | LOCK_NB) == -1) {
 		err = (errno == EWOULDBLOCK ? got_error(GOT_ERR_WORKTREE_BUSY)
-		    : got_error_prefix_errno("flock"));
+		    : got_error_prefix_errno2("flock", path));
 		goto done;
 	}
 
 	if (lstat(path, &sb) != 0) {
-		err = got_error_prefix_errno(path);
+		err = got_error_prefix_errno2("lstat", path);
 		goto done;
 	}
 	*content = calloc(1, sb.st_size);
@@ -174,7 +174,7 @@ read_meta_file(char **content, const char *path_got, c
 
 	n = read(fd, *content, sb.st_size);
 	if (n != sb.st_size) {
-		err = (n == -1 ? got_error_prefix_errno(path) :
+		err = (n == -1 ? got_error_prefix_errno2("read", path) :
 		    got_error(GOT_ERR_WORKTREE_META));
 		goto done;
 	}
@@ -186,7 +186,7 @@ read_meta_file(char **content, const char *path_got, c
 
 done:
 	if (fd != -1 && close(fd) == -1 && err == NULL)
-		err = got_error_prefix_errno(path_got);
+		err = got_error_prefix_errno2("close", path_got);
 	free(path);
 	if (err) {
 		free(*content);
@@ -227,12 +227,12 @@ got_worktree_init(const char *path, struct got_referen
 
 	if (!got_path_is_absolute(prefix)) {
 		if (asprintf(&absprefix, "/%s", prefix) == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("asprintf");
 	}
 
 	/* Create top-level directory (may already exist). */
 	if (mkdir(path, GOT_DEFAULT_DIR_MODE) == -1 && errno != EEXIST) {
-		err = got_error_prefix_errno(path);
+		err = got_error_prefix_errno2("mkdir", path);
 		goto done;
 	}
 
@@ -242,7 +242,7 @@ got_worktree_init(const char *path, struct got_referen
 		goto done;
 	}
 	if (mkdir(path_got, GOT_DEFAULT_DIR_MODE) == -1 && errno != EEXIST) {
-		err = got_error_prefix_errno(path_got);
+		err = got_error_prefix_errno2("mkdir", path_got);
 		goto done;
 	}
 
@@ -259,7 +259,7 @@ got_worktree_init(const char *path, struct got_referen
 	/* Write the HEAD reference. */
 	refstr = got_ref_to_str(head_ref);
 	if (refstr == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_ref_to_str");
 		goto done;
 	}
 	err = create_meta_file(path_got, GOT_WORKTREE_HEAD_REF, refstr);
@@ -352,7 +352,7 @@ open_worktree(struct got_worktree **worktree, const ch
 	fd = open(path_lock, O_RDWR | O_EXLOCK | O_NONBLOCK);
 	if (fd == -1) {
 		err = (errno == EWOULDBLOCK ? got_error(GOT_ERR_WORKTREE_BUSY)
-		    : got_error_prefix_errno(path_lock));
+		    : got_error_prefix_errno2("open", path_lock));
 		goto done;
 	}
 
@@ -450,7 +450,7 @@ got_worktree_open(struct got_worktree **worktree, cons
 			return NULL;
 		path = dirname(path);
 		if (path == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno2("dirname", path);
 	} while (!((path[0] == '.' || path[0] == '/') && path[1] == '\0'));
 
 	return got_error(GOT_ERR_NOT_WORKTREE);
@@ -467,7 +467,8 @@ got_worktree_close(struct got_worktree *worktree)
 	free(worktree->head_ref_name);
 	if (worktree->lockfd != -1)
 		if (close(worktree->lockfd) != 0)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("close",
+			    got_worktree_get_root_path(worktree));
 	free(worktree);
 	return err;
 }
@@ -570,7 +571,8 @@ lock_worktree(struct got_worktree *worktree, int opera
 {
 	if (flock(worktree->lockfd, operation | LOCK_NB) == -1)
 		return (errno == EWOULDBLOCK ? got_error(GOT_ERR_WORKTREE_BUSY)
-		    : got_error_prefix_errno("flock"));
+		    : got_error_prefix_errno2("flock",
+		    got_worktree_get_root_path(worktree)));
 	return NULL;
 }
 
@@ -588,7 +590,7 @@ add_dir_on_disk(struct got_worktree *worktree, const c
 		struct stat sb;
 		err = NULL;
 		if (lstat(abspath, &sb) == -1) {
-			err = got_error_prefix_errno("lstat");
+			err = got_error_prefix_errno2("lstat", abspath);
 		} else if (!S_ISDIR(sb.st_mode)) {
 			/* TODO directory is obstructed; do something */
 			err = got_error(GOT_ERR_FILE_OBSTRUCTED);
@@ -608,15 +610,15 @@ check_file_contents_equal(int *same, FILE *f1, FILE *f
 
 	*same = 1;
 
-	while (1) {
+	for (;;) {
 		flen1 = fread(fbuf1, 1, sizeof(fbuf1), f1);
 		if (flen1 == 0 && ferror(f1)) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fread");
 			break;
 		}
 		flen2 = fread(fbuf2, 1, sizeof(fbuf2), f2);
 		if (flen2 == 0 && ferror(f2)) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fread");
 			break;
 		}
 		if (flen1 == 0) {
@@ -652,13 +654,13 @@ check_files_equal(int *same, const char *f1_path, cons
 	*same = 1;
 
 	if (lstat(f1_path, &sb) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("lstat", f1_path);
 		goto done;
 	}
 	size1 = sb.st_size;
 
 	if (lstat(f2_path, &sb) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("lstat", f2_path);
 		goto done;
 	}
 	size2 = sb.st_size;
@@ -670,20 +672,20 @@ check_files_equal(int *same, const char *f1_path, cons
 
 	f1 = fopen(f1_path, "r");
 	if (f1 == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("open", f1_path);
 
 	f2 = fopen(f2_path, "r");
 	if (f2 == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("open", f2_path);
 		goto done;
 	}
 
 	err = check_file_contents_equal(same, f1, f2);
 done:
 	if (f1 && fclose(f1) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	if (f2 && fclose(f2) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 
 	return err;
 }
@@ -713,10 +715,10 @@ merge_blob(struct got_worktree *worktree, struct got_f
 
 	parent = dirname(ondisk_path);
 	if (parent == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("dirname", ondisk_path);
 
 	if (asprintf(&base_path, "%s/got-merged", parent) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("asprintf");
 
 	err = got_opentemp_named_fd(&merged_path, &merged_fd, base_path);
 	if (err)
@@ -724,7 +726,7 @@ merge_blob(struct got_worktree *worktree, struct got_f
 
 	free(base_path);
 	if (asprintf(&base_path, "%s/got-merge-blob1", parent) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		base_path = NULL;
 		goto done;
 	}
@@ -738,7 +740,7 @@ merge_blob(struct got_worktree *worktree, struct got_f
 
 	free(base_path);
 	if (asprintf(&base_path, "%s/got-merge-blob2", parent) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		base_path = NULL;
 		goto done;
 	}
@@ -767,7 +769,7 @@ merge_blob(struct got_worktree *worktree, struct got_f
 	if (err)
 		goto done;
 	if (asprintf(&label1, "commit %s", id_str) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 
@@ -779,9 +781,8 @@ merge_blob(struct got_worktree *worktree, struct got_f
 	(*progress_cb)(progress_arg,
 	    overlapcnt > 0 ? GOT_STATUS_CONFLICT : GOT_STATUS_MERGE, path);
 
-
 	if (fsync(merged_fd) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fsync");
 		goto done;
 	}
 
@@ -794,12 +795,13 @@ merge_blob(struct got_worktree *worktree, struct got_f
 	}
 
 	if (chmod(merged_path, st_mode) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("chmod", merged_path);
 		goto done;
 	}
 
 	if (rename(merged_path, ondisk_path) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno3("rename", merged_path,
+		    ondisk_path);
 		unlink(merged_path);
 		goto done;
 	}
@@ -812,11 +814,11 @@ merge_blob(struct got_worktree *worktree, struct got_f
 	    blob1->id.sha1, worktree->base_commit_id->sha1, update_timestamps);
 done:
 	if (merged_fd != -1 && close(merged_fd) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	if (f1 && fclose(f1) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	if (f2 && fclose(f2) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	if (blob2)
 		got_object_blob_close(blob2);
 	free(merged_path);
@@ -877,7 +879,7 @@ install_blob(struct got_worktree *worktree, const char
 		if (errno == ENOENT) {
 			char *parent = dirname(path);
 			if (parent == NULL)
-				return got_error_from_errno();
+				return got_error_prefix_errno2("dirname", path);
 			err = add_dir_on_disk(worktree, parent);
 			if (err)
 				return err;
@@ -885,7 +887,8 @@ install_blob(struct got_worktree *worktree, const char
 			    O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW,
 			    GOT_DEFAULT_FILE_MODE);
 			if (fd == -1)
-				return got_error_from_errno();
+				return got_error_prefix_errno2("open",
+				    ondisk_path);
 		} else if (errno == EEXIST) {
 			if (!S_ISREG(st_mode)) {
 				/* TODO file is obstructed; do something */
@@ -899,7 +902,7 @@ install_blob(struct got_worktree *worktree, const char
 				update = 1;
 			}
 		} else
-			return got_error_from_errno();
+			return got_error_prefix_errno2("open", ondisk_path);
 	}
 
 	if (restoring_missing_file)
@@ -920,7 +923,7 @@ install_blob(struct got_worktree *worktree, const char
 			/* Skip blob object header first time around. */
 			ssize_t outlen = write(fd, buf + hdrlen, len - hdrlen);
 			if (outlen == -1) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("write");
 				goto done;
 			} else if (outlen != len - hdrlen) {
 				err = got_error(GOT_ERR_IO);
@@ -931,13 +934,14 @@ install_blob(struct got_worktree *worktree, const char
 	} while (len != 0);
 
 	if (fsync(fd) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fsync");
 		goto done;
 	}
 
 	if (update) {
 		if (rename(tmppath, ondisk_path) != 0) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno3("rename", tmppath,
+			    ondisk_path);
 			unlink(tmppath);
 			goto done;
 		}
@@ -945,19 +949,19 @@ install_blob(struct got_worktree *worktree, const char
 
 	if (te_mode & S_IXUSR) {
 		if (chmod(ondisk_path, st_mode | S_IXUSR) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("chmod", ondisk_path);
 			goto done;
 		}
 	} else {
 		if (chmod(ondisk_path, st_mode & ~S_IXUSR) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("chmod", ondisk_path);
 			goto done;
 		}
 	}
 
 done:
 	if (fd != -1 && close(fd) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	free(tmppath);
 	return err;
 }
@@ -1026,7 +1030,7 @@ get_file_status(unsigned char *status, struct stat *sb
 				sb->st_mode = GOT_DEFAULT_FILE_MODE;
 			return NULL;
 		}
-		return got_error_from_errno();
+		return got_error_prefix_errno2("lstat", abspath);
 	}
 
 	if (!S_ISREG(sb->st_mode)) {
@@ -1060,7 +1064,7 @@ get_file_status(unsigned char *status, struct stat *sb
 
 	f = fopen(abspath, "r");
 	if (f == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("fopen", abspath);
 		goto done;
 	}
 	hdrlen = got_object_blob_get_hdrlen(blob);
@@ -1072,7 +1076,7 @@ get_file_status(unsigned char *status, struct stat *sb
 		/* Skip length of blob object header first time around. */
 		flen = fread(fbuf, 1, sizeof(fbuf) - hdrlen, f);
 		if (flen == 0 && ferror(f)) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fread");
 			goto done;
 		}
 		if (blen == 0) {
@@ -1122,7 +1126,7 @@ update_blob(struct got_worktree *worktree,
 	struct stat sb;
 
 	if (asprintf(&ondisk_path, "%s/%s", worktree->root_path, path) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("asprintf");
 
 	err = get_file_status(&status, &sb, ie, ondisk_path, repo);
 	if (err)
@@ -1185,17 +1189,18 @@ remove_ondisk_file(const char *root_path, const char *
 	char *ondisk_path = NULL;
 
 	if (asprintf(&ondisk_path, "%s/%s", root_path, path) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("asprintf");
 
 	if (unlink(ondisk_path) == -1) {
 		if (errno != ENOENT)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("unlink", ondisk_path);
 	} else {
 		char *parent = dirname(ondisk_path);
 		while (parent && strcmp(parent, root_path) != 0) {
 			if (rmdir(parent) == -1) {
 				if (errno != ENOTEMPTY)
-					err = got_error_from_errno();
+					err = got_error_prefix_errno2("rmdir",
+					    parent);
 				break;
 			}
 			parent = dirname(parent);
@@ -1218,7 +1223,7 @@ delete_blob(struct got_worktree *worktree, struct got_
 
 	if (asprintf(&ondisk_path, "%s/%s", worktree->root_path, ie->path)
 	    == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("asprintf");
 
 	err = get_file_status(&status, &sb, ie, ondisk_path, repo);
 	if (err)
@@ -1296,7 +1301,7 @@ diff_new(void *arg, struct got_tree_entry *te, const c
 	if (asprintf(&path, "%s%s%s", parent_path,
 	    parent_path[0] ? "/" : "", te->name)
 	    == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("asprintf");
 
 	if (S_ISDIR(te->mode))
 		err = add_dir_on_disk(a->worktree, path);
@@ -1323,7 +1328,7 @@ got_worktree_get_base_ref_name(char **refname, struct 
 
 	if (asprintf(refname, "%s-%s", GOT_WORKTREE_BASE_REF_PREFIX, uuidstr)
 	    == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		*refname = NULL;
 	}
 	free(uuidstr);
@@ -1367,11 +1372,11 @@ open_fileindex(struct got_fileindex **fileindex, char 
 	*fileindex_path = NULL;
 	*fileindex = got_fileindex_alloc();
 	if (*fileindex == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("got_fileindex_alloc");
 
 	if (asprintf(fileindex_path, "%s/%s/%s", worktree->root_path,
 	    GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		*fileindex_path = NULL;
 		goto done;
 	}
@@ -1379,11 +1384,11 @@ open_fileindex(struct got_fileindex **fileindex, char 
 	index = fopen(*fileindex_path, "rb");
 	if (index == NULL) {
 		if (errno != ENOENT)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("fopen", *fileindex_path);
 	} else {
 		err = got_fileindex_read(*fileindex, index);
 		if (fclose(index) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fclose");
 	}
 done:
 	if (err) {
@@ -1443,13 +1448,13 @@ got_worktree_checkout_files(struct got_worktree *workt
 		int obj_type;
 		relpath = strdup(path);
 		if (relpath == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("strdup");
 			goto done;
 		}
 		if (asprintf(&tree_path, "%s%s%s", worktree->path_prefix,
 		    got_path_is_root_dir(worktree->path_prefix) ? "" : "/",
 		    path) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("asprintf");
 			goto done;
 		}
 		err = got_object_id_by_path(&tree_id, repo,
@@ -1465,12 +1470,12 @@ got_worktree_checkout_files(struct got_worktree *workt
 			if (strchr(path, '/')  == NULL) {
 				relpath = strdup("");
 				if (relpath == NULL) {
-					err = got_error_from_errno();
+					err = got_error_prefix_errno("strdup");
 					goto done;
 				}
 				tree_path = strdup(worktree->path_prefix);
 				if (tree_path == NULL) {
-					err = got_error_from_errno();
+					err = got_error_prefix_errno("strdup");
 					goto done;
 				}
 			} else {
@@ -1482,7 +1487,7 @@ got_worktree_checkout_files(struct got_worktree *workt
 				    got_path_is_root_dir(
 				    worktree->path_prefix) ? "" : "/",
 				    relpath) == -1) {
-					err = got_error_from_errno();
+					err = got_error_prefix_errno("asprintf");
 					goto done;
 				}
 			}
@@ -1493,14 +1498,14 @@ got_worktree_checkout_files(struct got_worktree *workt
 				goto done;
 			entry_name = basename(path);
 			if (entry_name == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno2("basename", path);
 				goto done;
 			}
 		}
 	} else {
 		relpath = strdup("");
 		if (relpath == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("strdup");
 			goto done;
 		}
 		err = got_object_id_by_path(&tree_id, repo,
@@ -1538,7 +1543,8 @@ got_worktree_checkout_files(struct got_worktree *workt
 		goto done;
 
 	if (rename(new_fileindex_path, fileindex_path) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno3("rename", new_fileindex_path,
+		    fileindex_path);
 		unlink(new_fileindex_path);
 		goto done;
 	}
@@ -1615,11 +1621,11 @@ status_old_new(void *arg, struct got_fileindex_entry *
 	if (parent_path[0]) {
 		if (asprintf(&abspath, "%s/%s/%s", a->worktree->root_path,
 		    parent_path, de->d_name) == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("asprintf");
 	} else {
 		if (asprintf(&abspath, "%s/%s", a->worktree->root_path,
 		    de->d_name) == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("asprintf");
 	}
 
 	err = report_file_status(ie, abspath, a->status_cb, a->status_arg,
@@ -1671,7 +1677,7 @@ status_new(void *arg, struct dirent *de, const char *p
 
 	if (parent_path[0]) {
 		if (asprintf(&path, "%s/%s", parent_path, de->d_name) == -1)
-			return got_error_from_errno();
+			return got_error_prefix_errno("asprintf");
 	} else {
 		path = de->d_name;
 	}
@@ -1699,13 +1705,13 @@ got_worktree_status(struct got_worktree *worktree, con
 
 	fileindex = got_fileindex_alloc();
 	if (fileindex == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_fileindex_alloc");
 		goto done;
 	}
 
 	if (asprintf(&fileindex_path, "%s/%s/%s", worktree->root_path,
 	    GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		fileindex_path = NULL;
 		goto done;
 	}
@@ -1713,7 +1719,7 @@ got_worktree_status(struct got_worktree *worktree, con
 	index = fopen(fileindex_path, "rb");
 	if (index == NULL) {
 		if (errno != ENOENT) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("fopen", fileindex_path);
 			goto done;
 		}
 	} else {
@@ -1725,7 +1731,7 @@ got_worktree_status(struct got_worktree *worktree, con
 
 	if (asprintf(&ondisk_path, "%s%s%s",
 	    worktree->root_path, path[0] ? "/" : "", path) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 	workdir = opendir(ondisk_path);
@@ -1741,7 +1747,7 @@ got_worktree_status(struct got_worktree *worktree, con
 			    status_cb, status_arg, repo);
 			goto done;
 		} else {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("opendir", ondisk_path);
 			goto done;
 		}
 	}
@@ -1780,7 +1786,7 @@ got_worktree_resolve_path(char **wt_path, struct got_w
 
 	resolved = realpath(arg, NULL);
 	if (resolved == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("realpath", arg);
 
 	if (strncmp(got_worktree_get_root_path(worktree), resolved,
 	    strlen(got_worktree_get_root_path(worktree)))) {
@@ -1791,7 +1797,7 @@ got_worktree_resolve_path(char **wt_path, struct got_w
 	path = strdup(resolved +
 	    strlen(got_worktree_get_root_path(worktree)) + 1 /* skip '/' */);
 	if (path == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		goto done;
 	}
 
@@ -1833,20 +1839,20 @@ got_worktree_schedule_add(struct got_worktree *worktre
 
 	fileindex = got_fileindex_alloc();
 	if (fileindex == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_fileindex_alloc");
 		goto done;
 	}
 
 	if (asprintf(&fileindex_path, "%s/%s/%s", worktree->root_path,
 	    GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		fileindex_path = NULL;
 		goto done;
 	}
 
 	index = fopen(fileindex_path, "rb");
 	if (index == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("fopen", fileindex_path);
 		goto done;
 	}
 
@@ -1878,7 +1884,8 @@ got_worktree_schedule_add(struct got_worktree *worktre
 		goto done;
 
 	if (rename(new_fileindex_path, fileindex_path) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno3("rename", new_fileindex_path,
+		    fileindex_path);
 		goto done;
 	}
 
@@ -1889,11 +1896,12 @@ got_worktree_schedule_add(struct got_worktree *worktre
 done:
 	if (index) {
 		if (fclose(index) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fclose");
 	}
 	if (new_fileindex_path) {
 		if (unlink(new_fileindex_path) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("unlink",
+			    new_fileindex_path);
 		free(new_fileindex_path);
 	}
 	if (ie && !ie_added)
@@ -1932,20 +1940,20 @@ got_worktree_schedule_delete(struct got_worktree *work
 
 	fileindex = got_fileindex_alloc();
 	if (fileindex == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_fileindex_alloc");
 		goto done;
 	}
 
 	if (asprintf(&fileindex_path, "%s/%s/%s", worktree->root_path,
 	    GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		fileindex_path = NULL;
 		goto done;
 	}
 
 	index = fopen(fileindex_path, "rb");
 	if (index == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("fopen", fileindex_path);
 		goto done;
 	}
 
@@ -1979,7 +1987,7 @@ got_worktree_schedule_delete(struct got_worktree *work
 	}
 
 	if (unlink(ondisk_path) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("unlink", ondisk_path);
 		goto done;
 	}
 
@@ -1995,7 +2003,8 @@ got_worktree_schedule_delete(struct got_worktree *work
 		goto done;
 
 	if (rename(new_fileindex_path, fileindex_path) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno3("rename", new_fileindex_path,
+		    fileindex_path);
 		goto done;
 	}
 
@@ -2007,11 +2016,12 @@ done:
 	free(relpath);
 	if (index) {
 		if (fclose(index) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fclose");
 	}
 	if (new_fileindex_path) {
 		if (unlink(new_fileindex_path) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("unlink",
+			    new_fileindex_path);
 		free(new_fileindex_path);
 	}
 	if (fileindex)
@@ -2052,20 +2062,20 @@ got_worktree_revert(struct got_worktree *worktree,
 
 	fileindex = got_fileindex_alloc();
 	if (fileindex == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_fileindex_alloc");
 		goto done;
 	}
 
 	if (asprintf(&fileindex_path, "%s/%s/%s", worktree->root_path,
 	    GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		fileindex_path = NULL;
 		goto done;
 	}
 
 	index = fopen(fileindex_path, "rb");
 	if (index == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("fopen", fileindex_path);
 		goto done;
 	}
 
@@ -2089,20 +2099,20 @@ got_worktree_revert(struct got_worktree *worktree,
 	if (got_path_is_root_dir(worktree->path_prefix)) {
 		tree_path = strdup(parent_path);
 		if (tree_path == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("strdup");
 			goto done;
 		}
 	} else {
 		if (got_path_is_root_dir(parent_path)) {
 			tree_path = strdup(worktree->path_prefix);
 			if (tree_path == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("strdup");
 				goto done;
 			}
 		} else {
 			if (asprintf(&tree_path, "%s/%s",
 			    worktree->path_prefix, parent_path) == -1) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("asprintf");
 				goto done;
 			}
 		}
@@ -2119,7 +2129,7 @@ got_worktree_revert(struct got_worktree *worktree,
 
 	te_name = basename(ie->path);
 	if (te_name == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("basename", ie->path);
 		goto done;
 	}
 
@@ -2172,7 +2182,8 @@ got_worktree_revert(struct got_worktree *worktree,
 		goto done;
 
 	if (rename(new_fileindex_path, fileindex_path) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno3("rename", new_fileindex_path,
+		    fileindex_path);
 		goto done;
 	}
 
@@ -2188,11 +2199,12 @@ done:
 	free(tree_id);
 	if (index) {
 		if (fclose(index) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fclose");
 	}
 	if (new_fileindex_path) {
 		if (unlink(new_fileindex_path) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("unlink",
+			    new_fileindex_path);
 		free(new_fileindex_path);
 	}
 	if (fileindex)
@@ -2249,13 +2261,13 @@ collect_commitables(void *arg, unsigned char status, c
 		return NULL;
 
 	if (asprintf(&path, "/%s", relpath) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 	if (strcmp(path, "/") == 0) {
 		parent_path = strdup("");
 		if (parent_path == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno("strdup");
 	} else {
 		err = got_path_dirname(&parent_path, path);
 		if (err)
@@ -2264,20 +2276,20 @@ collect_commitables(void *arg, unsigned char status, c
 
 	ct = calloc(1, sizeof(*ct));
 	if (ct == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("calloc");
 		goto done;
 	}
 
 	if (asprintf(&ct->ondisk_path, "%s/%s", a->worktree->root_path,
 	    relpath) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 	if (status == GOT_STATUS_DELETE) {
 		sb.st_mode = GOT_DEFAULT_FILE_MODE;
 	} else {
 		if (lstat(ct->ondisk_path, &sb) != 0) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno2("lstat", ct->ondisk_path);
 			goto done;
 		}
 		ct->mode = sb.st_mode;
@@ -2286,7 +2298,7 @@ collect_commitables(void *arg, unsigned char status, c
 	if (asprintf(&ct->in_repo_path, "%s%s%s", a->worktree->path_prefix,
 	    got_path_is_root_dir(a->worktree->path_prefix) ? "" : "/",
 	    relpath) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 
@@ -2295,13 +2307,13 @@ collect_commitables(void *arg, unsigned char status, c
 	if (ct->status != GOT_STATUS_ADD) {
 		ct->base_id = got_object_id_dup(id);
 		if (ct->base_id == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("got_object_id_dup");
 			goto done;
 		}
 	}
 	ct->path = strdup(path);
 	if (ct->path == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		goto done;
 	}
 	err = got_pathlist_insert(&new, a->commitable_paths, ct->path, ct);
@@ -2331,7 +2343,7 @@ write_subtree(struct got_object_id **new_subtree_id,
 
 	if (asprintf(&subpath, "%s%s%s", parent_path,
 	    got_path_is_root_dir(parent_path) ? "" : "/", te->name) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("asprintf");
 
 	err = got_object_open_as_tree(&subtree, repo, te->id);
 	if (err)
@@ -2388,7 +2400,7 @@ alloc_modified_blob_tree_entry(struct got_tree_entry *
 	free((*new_te)->id);
 	(*new_te)->id = got_object_id_dup(ct->blob_id);
 	if ((*new_te)->id == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_object_id_dup");
 		goto done;
 	}
 done:
@@ -2410,16 +2422,16 @@ alloc_added_blob_tree_entry(struct got_tree_entry **ne
 
 	*new_te = calloc(1, sizeof(**new_te));
 	if (*new_te == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	ct_name = basename(ct->path);
 	if (ct_name == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno2("basename", ct->path);
 		goto done;
 	}
 	(*new_te)->name = strdup(ct_name);
 	if ((*new_te)->name == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		goto done;
 	}
 
@@ -2427,7 +2439,7 @@ alloc_added_blob_tree_entry(struct got_tree_entry **ne
 
 	(*new_te)->id = got_object_id_dup(ct->blob_id);
 	if ((*new_te)->id == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_object_id_dup");
 		goto done;
 	}
 done:
@@ -2476,7 +2488,7 @@ match_modified_subtree(int *modified, struct got_tree_
 	if (asprintf(&te_path, "%s%s%s", base_tree_path,
 	    got_path_is_root_dir(base_tree_path) ? "" : "/",
 	    te->name) == -1)
-		return got_error_from_errno();
+		return got_error_prefix_errno("asprintf");
 
 	TAILQ_FOREACH(pe, commitable_paths, entry) {
 		struct commitable *ct = pe->data;
@@ -2520,7 +2532,7 @@ match_deleted_or_modified_ct(struct commitable **ctp,
 
 		ct_name = basename(pe->path);
 		if (ct_name == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno2("basename", pe->path);
 
 		if (strcmp(te->name, ct_name) != 0)
 			continue;
@@ -2584,7 +2596,7 @@ write_tree(struct got_object_id **new_tree_id,
 			if (asprintf(&subtree_path, "%s%s%s", path_base_tree,
 			    got_path_is_root_dir(path_base_tree) ? "" : "/",
 			    child_path) == -1) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("asprintf");
 				goto done;
 			}
 			TAILQ_FOREACH(pe2, &paths, entry) {
@@ -2602,7 +2614,7 @@ write_tree(struct got_object_id **new_tree_id,
 			new_te->mode = S_IFDIR;
 			new_te->name = strdup(child_path);
 			if (new_te->name == NULL) {
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("strdup");
 				got_object_tree_entry_close(new_te);
 				new_te = NULL;
 				goto done;
@@ -2741,7 +2753,8 @@ update_fileindex_after_commit(struct got_pathlist_head
 		goto done;
 
 	if (rename(new_fileindex_path, fileindex_path) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno3("rename", new_fileindex_path,
+		    fileindex_path);
 		unlink(new_fileindex_path);
 		goto done;
 	}
@@ -2875,7 +2888,7 @@ got_worktree_commit(struct got_object_id **new_commit_
 
 		if (asprintf(&ondisk_path, "%s/%s",
 		    worktree->root_path, pe->path) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("asprintf");
 			goto done;
 		}
 		err = got_object_blob_create(&ct->blob_id, ondisk_path, repo);
@@ -2904,7 +2917,7 @@ got_worktree_commit(struct got_object_id **new_commit_
 	/* XXX ideally we'd lock the reference file here to avoid a race */
 	head_ref_name = got_worktree_get_head_ref_name(worktree);
 	if (head_ref_name == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_worktree_get_head_ref_name");
 		goto done;
 	}
 	err = got_ref_open(&head_ref2, repo, head_ref_name);
blob - ce22859b7c7bf03af2235be4c66f5fed1eb18a1c
blob + d3ec83a5dfb13832659f54445a0d9650ca39b2bd
--- libexec/got-read-blob/got-read-blob.c
+++ libexec/got-read-blob/got-read-blob.c
@@ -61,7 +61,7 @@ main(int argc, char *argv[])
 #ifndef PROFILE
 	/* revoke access to most system calls */
 	if (pledge("stdio recvfd", NULL) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("pledge");
 		got_privsep_send_error(&ibuf, err);
 		return 1;
 	}
@@ -134,13 +134,13 @@ main(int argc, char *argv[])
 			goto done;
 
 		if (lseek(imsg.fd, SEEK_SET, 0) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("lseek");
 			goto done;
 		}
 
 		f = fdopen(imsg.fd, "rb");
 		if (f == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fdopen");
 			goto done;
 		}
 
@@ -163,14 +163,14 @@ main(int argc, char *argv[])
 done:
 		if (f) {
 			if (fclose(f) != 0 && err == NULL)
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("fclose");
 		} else if (imsg.fd != -1) {
 			if (close(imsg.fd) != 0 && err == NULL)
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("close");
 		}
 		if (imsg_outfd.fd != -1) {
 			if (close(imsg_outfd.fd) != 0 && err == NULL)
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("close");
 		}
 
 		imsg_free(&imsg);
@@ -189,6 +189,6 @@ done:
 		}
 	}
 	if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	return err ? 1 : 0;
 }
blob - e39345fd841e433db3512e2ca55ee8e9bb4cca89
blob + 649c1dfdbd77e28adf852332292db3055f22e10a
--- libexec/got-read-commit/got-read-commit.c
+++ libexec/got-read-commit/got-read-commit.c
@@ -95,7 +95,7 @@ main(int argc, char *argv[])
 #ifndef PROFILE
 	/* revoke access to most system calls */
 	if (pledge("stdio recvfd", NULL) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("pledge");
 		got_privsep_send_error(&ibuf, err);
 		return 1;
 	}
@@ -110,7 +110,7 @@ main(int argc, char *argv[])
 			err = got_error(GOT_ERR_CANCELLED);
 			break;
 		}
-	
+
 		err = got_privsep_recv_imsg(&imsg, &ibuf, 0);
 		if (err) {
 			if (err->code == GOT_ERR_PRIVSEP_PIPE)
@@ -134,7 +134,7 @@ main(int argc, char *argv[])
 		/* Always assume file offset zero. */
 		f = fdopen(imsg.fd, "rb");
 		if (f == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fdopen");
 			goto done;
 		}
 
@@ -146,10 +146,10 @@ main(int argc, char *argv[])
 done:
 		if (f) {
 			if (fclose(f) != 0 && err == NULL)
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("fclose");
 		} else if (imsg.fd != -1) {
 			if (close(imsg.fd) != 0 && err == NULL)
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("close");
 		}
 		imsg_free(&imsg);
 		if (err)
@@ -164,6 +164,6 @@ done:
 		}
 	}
 	if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	return err ? 1 : 0;
 }
blob - 6692587e2c5320fd5093c0bbd4105f54b5d384e2
blob + ffe426e785a72453402b5b64c6d1306de3554d80
--- libexec/got-read-object/got-read-object.c
+++ libexec/got-read-object/got-read-object.c
@@ -72,7 +72,7 @@ main(int argc, char *argv[])
 #ifndef PROFILE
 	/* revoke access to most system calls */
 	if (pledge("stdio recvfd", NULL) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("pledge");
 		got_privsep_send_error(&ibuf, err);
 		return 1;
 	}
@@ -112,7 +112,7 @@ main(int argc, char *argv[])
 		err = got_privsep_send_obj(&ibuf, obj);
 done:
 		if (close(imsg.fd) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("close");
 		imsg_free(&imsg);
 		if (obj)
 			got_object_close(obj);
@@ -128,6 +128,6 @@ done:
 		}
 	}
 	if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	return err ? 1 : 0;
 }
blob - f88d42c77cfffbd6eb66f4a8878b805983106bd8
blob + 251c3ea0acb9ef58282facae7c7754b11cc8c83e
--- libexec/got-read-pack/got-read-pack.c
+++ libexec/got-read-pack/got-read-pack.c
@@ -203,7 +203,7 @@ receive_file(FILE **f, struct imsgbuf *ibuf, int imsg_
 
 	*f = fdopen(imsg.fd, "w+");
 	if (*f == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fdopen");
 		close(imsg.fd);
 		goto done;
 	}
@@ -265,11 +265,11 @@ blob_request(struct imsg *imsg, struct imsgbuf *ibuf, 
 done:
 	free(buf);
 	if (outfile && fclose(outfile) != 0 && err == NULL)
-		err = got_error_from_errno();
-	if (basefile && fclose(basefile) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
+	if (basefile && fclose(basefile) != 0 && err == NULL)
+		err = got_error_prefix_errno("fclose");
 	if (accumfile && fclose(accumfile) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	if (obj)
 		got_object_close(obj);
 	if (err && err->code != GOT_ERR_PRIVSEP_PIPE)
@@ -342,7 +342,7 @@ receive_packidx(struct got_packidx **packidx, struct i
 
 	p = calloc(1, sizeof(*p));
 	if (p == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("calloc");
 		goto done;
 	}
 
@@ -366,11 +366,11 @@ receive_packidx(struct got_packidx **packidx, struct i
 	p->len = ipackidx.len;
 	p->fd = dup(imsg.fd);
 	if (p->fd == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("dup");
 		goto done;
 	}
 	if (lseek(p->fd, 0, SEEK_SET) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("lseek");
 		goto done;
 	}
 
@@ -408,7 +408,7 @@ receive_pack(struct got_pack **packp, struct imsgbuf *
 
 	pack = calloc(1, sizeof(*pack));
 	if (pack == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("calloc");
 		goto done;
 	}
 
@@ -432,16 +432,16 @@ receive_pack(struct got_pack **packp, struct imsgbuf *
 	pack->filesize = ipack.filesize;
 	pack->fd = dup(imsg.fd);
 	if (pack->fd == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("dup");
 		goto done;
 	}
 	if (lseek(pack->fd, 0, SEEK_SET) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("lseek");
 		goto done;
 	}
 	pack->path_packfile = strdup(ipack.path_packfile);
 	if (pack->path_packfile == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		goto done;
 	}
 
@@ -481,7 +481,7 @@ main(int argc, char *argv[])
 
 	err = got_object_cache_init(&objcache, GOT_OBJECT_CACHE_TYPE_OBJ);
 	if (err) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_object_cache_init");
 		got_privsep_send_error(&ibuf, err);
 		return 1;
 	}
@@ -489,7 +489,7 @@ main(int argc, char *argv[])
 #ifndef PROFILE
 	/* revoke access to most system calls */
 	if (pledge("stdio recvfd", NULL) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("pledge");
 		got_privsep_send_error(&ibuf, err);
 		return 1;
 	}
@@ -552,7 +552,7 @@ main(int argc, char *argv[])
 		}
 
 		if (imsg.fd != -1 && close(imsg.fd) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("close");
 		imsg_free(&imsg);
 		if (err)
 			break;
@@ -571,6 +571,6 @@ main(int argc, char *argv[])
 		}
 	}
 	if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	return err ? 1 : 0;
 }
blob - 62f4869c5952c26a84cda9fdfb57d6d634126247
blob + 4c84b09a452c2e366fe37c57a606d9f2a70d8f2b
--- libexec/got-read-tag/got-read-tag.c
+++ libexec/got-read-tag/got-read-tag.c
@@ -90,7 +90,7 @@ main(int argc, char *argv[])
 #ifndef PROFILE
 	/* revoke access to most system calls */
 	if (pledge("stdio recvfd", NULL) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("pledge");
 		got_privsep_send_error(&ibuf, err);
 		return 1;
 	}
@@ -129,7 +129,7 @@ main(int argc, char *argv[])
 		/* Always assume file offset zero. */
 		f = fdopen(imsg.fd, "rb");
 		if (f == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fdopen");
 			goto done;
 		}
 
@@ -141,10 +141,10 @@ main(int argc, char *argv[])
 done:
 		if (f) {
 			if (fclose(f) != 0 && err == NULL)
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("fclose");
 		} else if (imsg.fd != -1) {
 			if (close(imsg.fd) != 0 && err == NULL)
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("close");
 		}
 		imsg_free(&imsg);
 		if (err)
@@ -159,6 +159,6 @@ done:
 		}
 	}
 	if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	return err ? 1 : 0;
 }
blob - 3edf27d89335964dd646e739f9ce3963555a7bcf
blob + e7243456a6b1a3bbebf3eaaf8c7c8181ed373c77
--- libexec/got-read-tree/got-read-tree.c
+++ libexec/got-read-tree/got-read-tree.c
@@ -89,7 +89,7 @@ main(int argc, char *argv[])
 #ifndef PROFILE
 	/* revoke access to most system calls */
 	if (pledge("stdio recvfd", NULL) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("pledge");
 		got_privsep_send_error(&ibuf, err);
 		return 1;
 	}
@@ -104,7 +104,7 @@ main(int argc, char *argv[])
 			err = got_error(GOT_ERR_CANCELLED);
 			break;
 		}
-	
+
 		err = got_privsep_recv_imsg(&imsg, &ibuf, 0);
 		if (err) {
 			if (err->code == GOT_ERR_PRIVSEP_PIPE)
@@ -128,7 +128,7 @@ main(int argc, char *argv[])
 		/* Always assume file offset zero. */
 		f = fdopen(imsg.fd, "rb");
 		if (f == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fdopen");
 			goto done;
 		}
 
@@ -140,10 +140,10 @@ main(int argc, char *argv[])
 done:
 		if (f) {
 			if (fclose(f) != 0 && err == NULL)
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("fclose");
 		} else if (imsg.fd != -1) {
 			if (close(imsg.fd) != 0 && err == NULL)
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("close");
 		}
 		imsg_free(&imsg);
 		if (err)
@@ -158,6 +158,6 @@ done:
 		}
 	}
 	if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("close");
 	return err ? 1 : 0;
 }
blob - 4a49027df9609976dca32ab3d55e9d07182a7870
blob + 7310a6d1b805676beb32c6da1a10e6d0b2256d46
--- regress/delta/delta_test.c
+++ regress/delta/delta_test.c
@@ -73,7 +73,7 @@ delta_apply(void)
 
 		base_file = got_opentemp();
 		if (base_file == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("got_opentemp");
 			break;
 		}
 
@@ -87,7 +87,7 @@ delta_apply(void)
 		err = got_delta_apply(base_file, dt->delta, dt->delta_len,
 		    result_file, &result_len);
 		if (fclose(base_file) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fclose");
 		if (dt->expected == NULL) {
 			/* Invalid delta, expect an error. */
 			if (err == NULL)
blob - 226a2987eab9195fd4ae19601b7251b53aeb65f3
blob + a42e23795b0488e27d70d33563f89f50c7b77e47
--- regress/idset/idset_test.c
+++ regress/idset/idset_test.c
@@ -72,7 +72,7 @@ idset_add_remove_iter(void)
 
 	set = got_object_idset_alloc();
 	if (set == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_object_idset_alloc");
 		goto done;
 	}
 	if (got_object_idset_num_elements(set) != 0) {
blob - 8eb2dae3d768894303eff1d87c647c9d538b8096
blob + 780e093cbeaf08580d0021776e1a2cdfe7e8d209
--- regress/repository/repository_test.c
+++ regress/repository/repository_test.c
@@ -109,7 +109,7 @@ print_tree_object(struct got_object_id *id, char *pare
 		free(hex);
 
 		if (asprintf(&next_parent, "%s/%s", parent, te->name) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("asprintf");
 			break;
 		}
 
@@ -339,7 +339,7 @@ repo_diff_blob(const char *repo_path)
 		i++;
 	}
 	if (fclose(outfile) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	test_printf("\n");
 	if (i != nitems(expected_output) + 1) {
 		test_printf("number of lines expected: %d; actual: %d\n",
@@ -422,26 +422,26 @@ apply_unveil(const char *repo_path)
 	if (repo_path) {
 		normpath = got_path_normalize(repo_path);
 		if (normpath == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno("got_path_normalize");
 		if (unveil(normpath, "r") != 0) {
 			free(normpath);
-			return got_error_from_errno();
+			return got_error_prefix_errno2("unveil", normpath);
 		}
 		free(normpath);
 	}
 
 	if (unveil("/tmp", "rwc") != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("unveil", "/tmp");
 
 	if (unveil("/dev/null", "rwc") != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("unveil", "/dev/null");
 
 	error = got_privsep_unveil_exec_helpers();
 	if (error != NULL)
 		return error;
 
 	if (unveil(NULL, NULL) != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("unveil");
 
 	return NULL;
 }
blob - 473f50c361965f19299b520819cf1a0b17cc8e31
blob + 54bb129e75442480e7dd497a09270cae4611f0e5
--- regress/worktree/worktree_test.c
+++ regress/worktree/worktree_test.c
@@ -96,7 +96,7 @@ remove_worktree_base_ref(struct got_worktree *worktree
 		return err;
 
 	if (asprintf(&absrefname, "refs/%s", refname) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 	err = got_ref_open(&base_ref, repo, absrefname);
blob - 119f156a6803a5c838deca39273c603545bf28a2
blob + c6e552d2af90981f18e9f26da22af91f437469ef
--- tog/tog.c
+++ tog/tog.c
@@ -385,7 +385,7 @@ view_splitscreen(struct tog_view *view)
 		return err;
 
 	if (mvwin(view->window, view->begin_y, view->begin_x) == ERR)
-		return got_error_from_errno();
+		return got_error_prefix_errno("mvwin");
 
 	return NULL;
 }
@@ -406,7 +406,7 @@ view_fullscreen(struct tog_view *view)
 		return err;
 
 	if (mvwin(view->window, view->begin_y, view->begin_x) == ERR)
-		return got_error_from_errno();
+		return got_error_prefix_errno("mvwin");
 
 	return NULL;
 }
@@ -433,9 +433,9 @@ view_resize(struct tog_view *view)
 		ncols = view->ncols + (COLS - view->cols);
 
 	if (wresize(view->window, nlines, ncols) == ERR)
-		return got_error_from_errno();
+		return got_error_prefix_errno("wresize");
 	if (replace_panel(view->panel, view->window) == ERR)
-		return got_error_from_errno();
+		return got_error_prefix_errno("replace_panel");
 	wclear(view->window);
 
 	view->nlines = nlines;
@@ -801,7 +801,7 @@ mbs2ws(wchar_t **ws, size_t *wlen, const char *s)
 	if (*wlen == (size_t)-1) {
 		int vislen;
 		if (errno != EILSEQ)
-			return got_error_from_errno();
+			return got_error_prefix_errno("mbstowcs");
 
 		/* byte string invalid in current encoding; try to "fix" it */
 		err = got_mbsavis(&vis, &vislen, s);
@@ -809,19 +809,19 @@ mbs2ws(wchar_t **ws, size_t *wlen, const char *s)
 			return err;
 		*wlen = mbstowcs(NULL, vis, 0);
 		if (*wlen == (size_t)-1) {
-			err = got_error_from_errno(); /* give up */
+			err = got_error_prefix_errno("mbstowcs"); /* give up */
 			goto done;
 		}
 	}
 
 	*ws = calloc(*wlen + 1, sizeof(*ws));
 	if (*ws == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("calloc");
 		goto done;
 	}
 
 	if (mbstowcs(*ws, vis ? vis : s, *wlen) != *wlen)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("mbstowcs");
 done:
 	free(vis);
 	if (err) {
@@ -868,7 +868,7 @@ format_line(wchar_t **wlinep, int *widthp, const char 
 			i++;
 			break;
 		default:
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("wcwidth");
 			goto done;
 		}
 	}
@@ -911,7 +911,7 @@ build_refs_str(char **refs_str, struct got_reflist_hea
 		s = *refs_str;
 		if (asprintf(refs_str, "%s%s%s", s ? s : "",
 		    s ? ", " : "", name) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("asprintf");
 			free(s);
 			*refs_str = NULL;
 			break;
@@ -956,7 +956,7 @@ draw_commit(struct tog_view *view, struct got_commit_o
 
 	committer_time = got_object_commit_get_committer_time(commit);
 	if (localtime_r(&committer_time, &tm) == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("localtime_r");
 	if (strftime(datebuf, sizeof(datebuf), "%g/%m/%d ", &tm)
 	    >= sizeof(datebuf))
 		return got_error(GOT_ERR_NO_SPACE);
@@ -972,7 +972,7 @@ draw_commit(struct tog_view *view, struct got_commit_o
 
 	author = strdup(got_object_commit_get_author(commit));
 	if (author == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		goto done;
 	}
 	err = format_author(&wauthor, &author_width, author, avail - col);
@@ -990,7 +990,7 @@ draw_commit(struct tog_view *view, struct got_commit_o
 
 	logmsg0 = strdup(got_object_commit_get_logmsg(commit));
 	if (logmsg0 == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("strdup");
 		goto done;
 	}
 	logmsg = logmsg0;
@@ -1090,7 +1090,7 @@ queue_commits(struct got_commit_graph *graph, struct c
 			break;
 		entry = alloc_commit_queue_entry(commit, id);
 		if (entry == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("alloc_commit_queue_entry");
 			break;
 		}
 
@@ -1178,7 +1178,7 @@ draw_commits(struct tog_view *view, struct commit_queu
 	    entry ? entry->idx + 1 : 0, commits->ncommits,
 	    commits_needed > 0 ? "loading... " :
 	    (refs_str ? refs_str : "")) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 
@@ -1186,14 +1186,14 @@ draw_commits(struct tog_view *view, struct commit_queu
 		if (asprintf(&header, "commit %s %s%s",
 		    id_str ? id_str : "........................................",
 		    path, ncommits_str) == -1) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("asprintf");
 			header = NULL;
 			goto done;
 		}
 	} else if (asprintf(&header, "commit %s%s",
 	    id_str ? id_str : "........................................",
 	    ncommits_str) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		header = NULL;
 		goto done;
 	}
@@ -1227,7 +1227,7 @@ draw_commits(struct tog_view *view, struct commit_queu
 			break;
 		author = strdup(got_object_commit_get_author(entry->commit));
 		if (author == NULL) {
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("strdup");
 			goto done;
 		}
 		err = format_author(&wauthor, &width, author, COLS);
@@ -1387,7 +1387,7 @@ open_diff_view_for_commit(struct tog_view **new_view, 
 
 	diff_view = view_open(0, 0, 0, begin_x, TOG_VIEW_DIFF);
 	if (diff_view == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("view_open");
 
 	parent_id = SIMPLEQ_FIRST(got_object_commit_get_parent_ids(commit));
 	err = open_diff_view(diff_view, parent_id ? parent_id->id : NULL,
@@ -1413,7 +1413,7 @@ browse_commit(struct tog_view **new_view, int begin_x,
 
 	tree_view = view_open(0, 0, 0, begin_x, TOG_VIEW_TREE);
 	if (tree_view == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("view_open");
 
 	err = open_tree_view(tree_view, tree, entry->id, refs, repo);
 	if (err)
@@ -1553,7 +1553,7 @@ open_log_view(struct tog_view *view, struct got_object
 	s->repo = repo;
 	s->start_id = got_object_id_dup(start_id);
 	if (s->start_id == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_object_id_dup");
 		goto done;
 	}
 
@@ -1755,7 +1755,8 @@ input_log_view(struct tog_view **new_view, struct tog_
 				lv = view_open(view->nlines, view->ncols,
 				    view->begin_y, view->begin_x, TOG_VIEW_LOG);
 				if (lv == NULL)
-					return got_error_from_errno();
+					return got_error_prefix_errno(
+					    "view_open");
 				err = open_log_view(lv, s->start_id, s->refs,
 				    s->repo, parent_path, 0);
 				if (err)
@@ -1782,20 +1783,20 @@ apply_unveil(const char *repo_path, const char *worktr
 	const struct got_error *error;
 
 	if (repo_path && unveil(repo_path, "r") != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("unveil", repo_path);
 
 	if (worktree_path && unveil(worktree_path, "rwc") != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("unveil", worktree_path);
 
 	if (unveil("/tmp", "rwc") != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno2("unveil", "/tmp");
 
 	error = got_privsep_unveil_exec_helpers();
 	if (error != NULL)
 		return error;
 
 	if (unveil(NULL, NULL) != 0)
-		return got_error_from_errno();
+		return got_error_prefix_errno("unveil");
 
 	return NULL;
 }
@@ -1856,7 +1857,7 @@ cmd_log(int argc, char *argv[])
 
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("getcwd");
 		goto done;
 	}
 	error = got_worktree_open(&worktree, cwd);
@@ -1867,7 +1868,7 @@ cmd_log(int argc, char *argv[])
 	if (argc == 0) {
 		path = strdup("");
 		if (path == NULL) {
-			error = got_error_from_errno();
+			error = got_error_prefix_errno("strdup");
 			goto done;
 		}
 	} else if (argc == 1) {
@@ -1879,7 +1880,7 @@ cmd_log(int argc, char *argv[])
 		} else {
 			path = strdup(argv[0]);
 			if (path == NULL) {
-				error = got_error_from_errno();
+				error = got_error_prefix_errno("strdup");
 				goto done;
 			}
 		}
@@ -1889,7 +1890,7 @@ cmd_log(int argc, char *argv[])
 	repo_path = worktree ?
 	    strdup(got_worktree_get_repo_path(worktree)) : strdup(cwd);
 	if (repo_path == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("strdup");
 		goto done;
 	}
 
@@ -1918,7 +1919,7 @@ cmd_log(int argc, char *argv[])
 
 	view = view_open(0, 0, 0, 0, TOG_VIEW_LOG);
 	if (view == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("view_open");
 		goto done;
 	}
 	error = open_log_view(view, start_id, &refs, repo, path, 1);
@@ -2062,36 +2063,36 @@ write_commit_info(struct got_object_id *commit_id,
 
 	err = got_object_id_str(&id_str, commit_id);
 	if (err) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_object_id_str");
 		goto done;
 	}
 
 	if (fprintf(outfile, "commit %s%s%s%s\n", id_str, refs_str ? " (" : "",
 	    refs_str ? refs_str : "", refs_str ? ")" : "") < 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fprintf");
 		goto done;
 	}
 	if (fprintf(outfile, "from: %s\n",
 	    got_object_commit_get_author(commit)) < 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fprintf");
 		goto done;
 	}
 	committer_time = got_object_commit_get_committer_time(commit);
 	if (fprintf(outfile, "date: %s UTC\n",
 	    get_datestr(&committer_time, datebuf)) < 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fprintf");
 		goto done;
 	}
 	author = got_object_commit_get_author(commit);
 	committer = got_object_commit_get_committer(commit);
 	if (strcmp(author, committer) != 0 &&
 	    fprintf(outfile, "via: %s\n", committer) < 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fprintf");
 		goto done;
 	}
 	if (fprintf(outfile, "%s\n",
 	    got_object_commit_get_logmsg(commit)) < 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fprintf");
 		goto done;
 	}
 done:
@@ -2110,11 +2111,11 @@ create_diff(struct tog_diff_view_state *s)
 
 	f = got_opentemp();
 	if (f == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_opentemp");
 		goto done;
 	}
 	if (s->f && fclose(s->f) != 0) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 		goto done;
 	}
 	s->f = f;
@@ -2168,7 +2169,7 @@ create_diff(struct tog_diff_view_state *s)
 	}
 done:
 	if (f && fflush(f) != 0 && err == NULL)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fflush");
 	return err;
 }
 
@@ -2204,7 +2205,7 @@ open_diff_view(struct tog_view *view, struct got_objec
 	if (id1) {
 		view->state.diff.id1 = got_object_id_dup(id1);
 		if (view->state.diff.id1 == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno("got_object_id_dup");
 	} else
 		view->state.diff.id1 = NULL;
 
@@ -2212,7 +2213,7 @@ open_diff_view(struct tog_view *view, struct got_objec
 	if (view->state.diff.id2 == NULL) {
 		free(view->state.diff.id1);
 		view->state.diff.id1 = NULL;
-		return got_error_from_errno();
+		return got_error_prefix_errno("got_object_id_dup");
 	}
 	view->state.diff.f = NULL;
 	view->state.diff.first_displayed_line = 1;
@@ -2252,7 +2253,7 @@ close_diff_view(struct tog_view *view)
 	free(view->state.diff.id2);
 	view->state.diff.id2 = NULL;
 	if (view->state.diff.f && fclose(view->state.diff.f) == EOF)
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("fclose");
 	return err;
 }
 
@@ -2274,7 +2275,7 @@ show_diff_view(struct tog_view *view)
 
 	if (asprintf(&header, "diff %s %s",
 	    id_str1 ? id_str1 : "/dev/null", id_str2) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		free(id_str1);
 		free(id_str2);
 		return err;
@@ -2299,7 +2300,7 @@ set_selected_commit(struct tog_diff_view_state *s,
 	free(s->id2);
 	s->id2 = got_object_id_dup(entry->id);
 	if (s->id2 == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("got_object_id_dup");
 
 	err = got_object_open_as_commit(&selected_commit, s->repo, entry->id);
 	if (err)
@@ -2484,13 +2485,13 @@ cmd_diff(int argc, char *argv[])
 	} else if (argc == 2) {
 		repo_path = getcwd(NULL, 0);
 		if (repo_path == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno("getcwd");
 		id_str1 = argv[0];
 		id_str2 = argv[1];
 	} else if (argc == 3) {
 		repo_path = realpath(argv[0], NULL);
 		if (repo_path == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno2("realpath", argv[0]);
 		id_str1 = argv[1];
 		id_str2 = argv[2];
 	} else
@@ -2520,7 +2521,7 @@ cmd_diff(int argc, char *argv[])
 
 	view = view_open(0, 0, 0, 0, TOG_VIEW_DIFF);
 	if (view == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("view_open");
 		goto done;
 	}
 	error = open_diff_view(view, id1, id2, NULL, &refs, repo);
@@ -2572,7 +2573,7 @@ draw_blame(struct tog_view *view, struct got_object_id
 	werase(view->window);
 
 	if (asprintf(&line, "commit %s", id_str) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		free(id_str);
 		return err;
 	}
@@ -2594,7 +2595,7 @@ draw_blame(struct tog_view *view, struct got_object_id
 	    *first_displayed_line - 1 + selected_line, nlines,
 	    blame_complete ? "" : "annotating... ", path) == -1) {
 		free(id_str);
-		return got_error_from_errno();
+		return got_error_prefix_errno("asprintf");
 	}
 	free(id_str);
 	err = format_line(&wline, &width, line, view->ncols);
@@ -2700,7 +2701,7 @@ blame_cb(void *arg, int nlines, int lineno, struct got
 
 	line->id = got_object_id_dup(id);
 	if (line->id == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_object_id_dup");
 		goto done;
 	}
 	line->annotated = 1;
@@ -2777,7 +2778,7 @@ stop_blame(struct tog_blame *blame)
 	}
 	if (blame->f) {
 		if (fclose(blame->f) != 0 && err == NULL)
-			err = got_error_from_errno();
+			err = got_error_prefix_errno("fclose");
 		blame->f = NULL;
 	}
 	if (blame->lines) {
@@ -2824,7 +2825,7 @@ run_blame(struct tog_blame *blame, struct tog_view *vi
 		goto done;
 	blame->f = got_opentemp();
 	if (blame->f == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_opentemp");
 		goto done;
 	}
 	err = got_object_blob_dump_to_file(&blame->filesize, &blame->nlines,
@@ -2834,7 +2835,7 @@ run_blame(struct tog_blame *blame, struct tog_view *vi
 
 	blame->lines = calloc(blame->nlines, sizeof(*blame->lines));
 	if (blame->lines == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("calloc");
 		goto done;
 	}
 
@@ -2847,7 +2848,7 @@ run_blame(struct tog_blame *blame, struct tog_view *vi
 	blame->cb_args.nlines = blame->nlines;
 	blame->cb_args.commit_id = got_object_id_dup(commit_id);
 	if (blame->cb_args.commit_id == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_object_id_dup");
 		goto done;
 	}
 	blame->cb_args.quit = done;
@@ -2888,7 +2889,7 @@ open_blame_view(struct tog_view *view, char *path,
 	s->blame_complete = 0;
 	s->path = path;
 	if (s->path == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("open_blame_view");
 	s->repo = repo;
 	s->refs = refs;
 	s->commit_id = commit_id;
@@ -3105,7 +3106,7 @@ input_blame_view(struct tog_view **new_view, struct to
 			diff_view = view_open(0, 0, 0, begin_x, TOG_VIEW_DIFF);
 			if (diff_view == NULL) {
 				got_object_commit_close(commit);
-				err = got_error_from_errno();
+				err = got_error_prefix_errno("view_open");
 				break;
 			}
 			err = open_diff_view(diff_view, pid ? pid->id : NULL,
@@ -3214,7 +3215,7 @@ cmd_blame(int argc, char *argv[])
 
 	cwd = getcwd(NULL, 0);
 	if (cwd == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("getcwd");
 		goto done;
 	}
 	if (repo_path == NULL) {
@@ -3227,13 +3228,13 @@ cmd_blame(int argc, char *argv[])
 			repo_path =
 			    strdup(got_worktree_get_repo_path(worktree));
 			if (repo_path == NULL)
-				error = got_error_from_errno();
+				error = got_error_prefix_errno("strdup");
 			if (error)
 				goto done;
 		} else {
 			repo_path = strdup(cwd);
 			if (repo_path == NULL) {
-				error = got_error_from_errno();
+				error = got_error_prefix_errno("strdup");
 				goto done;
 			}
 		}
@@ -3257,7 +3258,7 @@ cmd_blame(int argc, char *argv[])
 		    prefix, (strcmp(prefix, "/") != 0) ? "/" : "",
 		    worktree_subdir, worktree_subdir[0] ? "/" : "",
 		    path) == -1) {
-			error = got_error_from_errno();
+			error = got_error_prefix_errno("asprintf");
 			goto done;
 		}
 		error = got_repo_map_path(&in_repo_path, repo, p, 0);
@@ -3288,7 +3289,7 @@ cmd_blame(int argc, char *argv[])
 
 	view = view_open(0, 0, 0, 0, TOG_VIEW_BLAME);
 	if (view == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("view_open");
 		goto done;
 	}
 	error = open_blame_view(view, in_repo_path, commit_id, &refs, repo);
@@ -3381,13 +3382,14 @@ draw_tree_entries(struct tog_view *view,
 		if (show_ids) {
 			err = got_object_id_str(&id_str, te->id);
 			if (err)
-				return got_error_from_errno();
+				return got_error_prefix_errno(
+				    "got_object_id_str");
 		}
 		if (asprintf(&line, "%s  %s%s", id_str ? id_str : "",
 		    te->name, S_ISDIR(te->mode) ? "/" :
 		    ((te->mode & S_IXUSR) ? "*" : "")) == -1) {
 			free(id_str);
-			return got_error_from_errno();
+			return got_error_prefix_errno("asprintf");
 		}
 		free(id_str);
 		err = format_line(&wline, &width, line, view->ncols);
@@ -3491,7 +3493,7 @@ tree_entry_path(char **path, struct tog_parent_trees *
 
 	*path = calloc(1, len);
 	if (path == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("calloc");
 
 	(*path)[0] = '/';
 	pt = TAILQ_LAST(parents, tog_parent_trees);
@@ -3536,7 +3538,7 @@ blame_tree_entry(struct tog_view **new_view, int begin
 
 	blame_view = view_open(0, 0, 0, begin_x, TOG_VIEW_BLAME);
 	if (blame_view == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("view_open");
 
 	err = open_blame_view(blame_view, path, commit_id, refs, repo);
 	if (err) {
@@ -3559,7 +3561,7 @@ log_tree_entry(struct tog_view **new_view, int begin_x
 
 	log_view = view_open(0, 0, 0, begin_x, TOG_VIEW_LOG);
 	if (log_view == NULL)
-		return got_error_from_errno();
+		return got_error_prefix_errno("view_open");
 
 	err = tree_entry_path(&path, parents, te);
 	if (err)
@@ -3590,7 +3592,7 @@ open_tree_view(struct tog_view *view, struct got_tree_
 		goto done;
 
 	if (asprintf(&s->tree_label, "commit %s", commit_id_str) == -1) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("asprintf");
 		goto done;
 	}
 
@@ -3599,7 +3601,7 @@ open_tree_view(struct tog_view *view, struct got_tree_
 	s->first_displayed_entry = SIMPLEQ_FIRST(&s->entries->head);
 	s->commit_id = got_object_id_dup(commit_id);
 	if (s->commit_id == NULL) {
-		err = got_error_from_errno();
+		err = got_error_prefix_errno("got_object_id_dup");
 		goto done;
 	}
 	s->refs = refs;
@@ -3785,7 +3787,7 @@ input_tree_view(struct tog_view **new_view, struct tog
 					break;
 				parent = calloc(1, sizeof(*parent));
 				if (parent == NULL) {
-					err = got_error_from_errno();
+					err = got_error_prefix_errno("calloc");
 					break;
 				}
 				parent->tree = s->tree;
@@ -3884,7 +3886,7 @@ cmd_tree(int argc, char *argv[])
 		struct got_worktree *worktree;
 		char *cwd = getcwd(NULL, 0);
 		if (cwd == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno("getcwd");
 		error = got_worktree_open(&worktree, cwd);
 		if (error && error->code != GOT_ERR_NOT_WORKTREE)
 			goto done;
@@ -3896,13 +3898,13 @@ cmd_tree(int argc, char *argv[])
 		} else
 			repo_path = cwd;
 		if (repo_path == NULL) {
-			error = got_error_from_errno();
+			error = got_error_prefix_errno("strdup");
 			goto done;
 		}
 	} else if (argc == 1) {
 		repo_path = realpath(argv[0], NULL);
 		if (repo_path == NULL)
-			return got_error_from_errno();
+			return got_error_prefix_errno2("realpath", argv[0]);
 	} else
 		usage_log();
 
@@ -3939,7 +3941,7 @@ cmd_tree(int argc, char *argv[])
 
 	view = view_open(0, 0, 0, 0, TOG_VIEW_TREE);
 	if (view == NULL) {
-		error = got_error_from_errno();
+		error = got_error_prefix_errno("view_open");
 		goto done;
 	}
 	error = open_tree_view(view, tree, commit_id, &refs, repo);
@@ -4049,7 +4051,8 @@ main(int argc, char *argv[])
 				if (error == NULL)
 					got_repo_close(repo);
 			} else
-				error = got_error_from_errno();
+				error = got_error_prefix_errno2("realpath",
+				    argv[0]);
 			if (error) {
 				if (hflag) {
 					fprintf(stderr, "%s: '%s' is not a "