const char * svn_err_best_message(svn_error_t *err, char *buf, apr_size_t bufsize) { /* Skip over any trace records. */ while (svn_error__is_tracing_link(err)) err = err->child; if (err->message) return err->message; else return svn_strerror(err->apr_err, buf, bufsize); }
/** * Build the error message from the svn error into buffer. This * method calls itselft recursively for all the chained errors * * @param err the subversion error * @param depth the depth of the call, used for formating * @param parent_apr_err the apr of the previous level, used for formating * @param buffer the buffer where the formated error message will * be stored */ void JNIUtil::assembleErrorMessage(svn_error_t *err, int depth, apr_status_t parent_apr_err, std::string &buffer) { // buffer for a single error message char errbuf[256]; /* Pretty-print the error */ /* Note: we can also log errors here someday. */ /* When we're recursing, don't repeat the top-level message if its * the same as before. */ if (depth == 0 || err->apr_err != parent_apr_err) { /* Is this a Subversion-specific error code? */ if ((err->apr_err > APR_OS_START_USEERR) && (err->apr_err <= APR_OS_START_CANONERR)) buffer.append(svn_strerror(err->apr_err, errbuf, sizeof(errbuf))); /* Otherwise, this must be an APR error code. */ else { /* Messages coming from apr_strerror are in the native encoding, it's a good idea to convert them to UTF-8. */ const char* utf8_message; apr_strerror(err->apr_err, errbuf, sizeof(errbuf)); svn_error_t* utf8_err = svn_utf_cstring_to_utf8( &utf8_message, errbuf, err->pool); if (utf8_err) { /* Use fuzzy transliteration instead. */ svn_error_clear(utf8_err); utf8_message = svn_utf_cstring_from_utf8_fuzzy(errbuf, err->pool); } buffer.append(utf8_message); } buffer.append("\n"); } if (err->message) buffer.append(_("svn: ")).append(err->message).append("\n"); if (err->child) assembleErrorMessage(err->child, depth + 1, err->apr_err, buffer); }
CString SVNPatch::GetErrorMessageForNode(svn_error_t* Err) const { CString msg; if (Err != NULL) { svn_error_t * ErrPtr = Err; if (ErrPtr->message) msg = CUnicodeUtils::GetUnicode(ErrPtr->message); else { char errbuf[256] = {0}; /* Is this a Subversion-specific error code? */ if ((ErrPtr->apr_err > APR_OS_START_USEERR) && (ErrPtr->apr_err <= APR_OS_START_CANONERR)) { msg = svn_strerror (ErrPtr->apr_err, errbuf, _countof (errbuf)); } /* Otherwise, this must be an APR error code. */ else { svn_error_t *temp_err = NULL; const char * err_string = NULL; temp_err = svn_utf_cstring_to_utf8(&err_string, apr_strerror (ErrPtr->apr_err, errbuf, _countof (errbuf)-1), ErrPtr->pool); if (temp_err) { svn_error_clear (temp_err); msg = _T("Can't recode error string from APR"); } else { msg = CUnicodeUtils::GetUnicode(err_string); } } } msg = CStringUtils::LinesWrap(msg, 80); } return msg; }
static void print_error(svn_error_t *err, FILE *stream, const char *prefix) { char errbuf[256]; const char *err_string; svn_error_t *temp_err = NULL; /* ensure initialized even if err->file == NULL */ /* Pretty-print the error */ /* Note: we can also log errors here someday. */ #ifdef SVN_DEBUG /* Note: err->file is _not_ in UTF-8, because it's expanded from the __FILE__ preprocessor macro. */ const char *file_utf8; if (err->file && !(temp_err = svn_utf_cstring_to_utf8(&file_utf8, err->file, err->pool))) svn_error_clear(svn_cmdline_fprintf(stream, err->pool, "%s:%ld", err->file, err->line)); else { svn_error_clear(svn_cmdline_fputs(SVN_FILE_LINE_UNDEFINED, stream, err->pool)); svn_error_clear(temp_err); } svn_error_clear(svn_cmdline_fprintf(stream, err->pool, ": (apr_err=%d)\n", err->apr_err)); #endif /* SVN_DEBUG */ /* "traced call" */ if (svn_error__is_tracing_link(err)) { /* Skip it. We already printed the file-line coordinates. */ } /* Only print the same APR error string once. */ else if (err->message) { svn_error_clear(svn_cmdline_fprintf(stream, err->pool, "%sE%06d: %s\n", prefix, err->apr_err, err->message)); } else { /* Is this a Subversion-specific error code? */ if ((err->apr_err > APR_OS_START_USEERR) && (err->apr_err <= APR_OS_START_CANONERR)) err_string = svn_strerror(err->apr_err, errbuf, sizeof(errbuf)); /* Otherwise, this must be an APR error code. */ else if ((temp_err = svn_utf_cstring_to_utf8 (&err_string, apr_strerror(err->apr_err, errbuf, sizeof(errbuf)), err->pool))) { svn_error_clear(temp_err); err_string = _("Can't recode error string from APR"); } svn_error_clear(svn_cmdline_fprintf(stream, err->pool, "%sE%06d: %s\n", prefix, err->apr_err, err_string)); } }
CString CAppUtils::GetErrorString(svn_error_t * Err) { CString msg; CString temp; char errbuf[256]; if (Err != NULL) { svn_error_t * ErrPtr = Err; if (ErrPtr->message) msg = CUnicodeUtils::GetUnicode(ErrPtr->message); else { /* Is this a Subversion-specific error code? */ if ((ErrPtr->apr_err > APR_OS_START_USEERR) && (ErrPtr->apr_err <= APR_OS_START_CANONERR)) msg = svn_strerror (ErrPtr->apr_err, errbuf, sizeof (errbuf)); /* Otherwise, this must be an APR error code. */ else { svn_error_t *temp_err = NULL; const char * err_string = NULL; temp_err = svn_utf_cstring_to_utf8(&err_string, apr_strerror (ErrPtr->apr_err, errbuf, sizeof (errbuf)-1), ErrPtr->pool); if (temp_err) { svn_error_clear (temp_err); msg = _T("Can't recode error string from APR"); } else { msg = CUnicodeUtils::GetUnicode(err_string); } } } while (ErrPtr->child) { ErrPtr = ErrPtr->child; msg += _T("\n"); if (ErrPtr->message) temp = CUnicodeUtils::GetUnicode(ErrPtr->message); else { /* Is this a Subversion-specific error code? */ if ((ErrPtr->apr_err > APR_OS_START_USEERR) && (ErrPtr->apr_err <= APR_OS_START_CANONERR)) temp = svn_strerror (ErrPtr->apr_err, errbuf, sizeof (errbuf)); /* Otherwise, this must be an APR error code. */ else { svn_error_t *temp_err = NULL; const char * err_string = NULL; temp_err = svn_utf_cstring_to_utf8(&err_string, apr_strerror (ErrPtr->apr_err, errbuf, sizeof (errbuf)-1), ErrPtr->pool); if (temp_err) { svn_error_clear (temp_err); temp = _T("Can't recode error string from APR"); } else { temp = CUnicodeUtils::GetUnicode(err_string); } } } msg += temp; } return msg; } return _T(""); }
CString SVNBase::GetErrorString(svn_error_t * Err, int wrap /* = 80 */) { CString msg; CString temp; if (Err != NULL) { char errbuf[256] = { 0 }; svn_error_t * ErrPtr = Err; if (ErrPtr->message) msg = CUnicodeUtils::GetUnicode(ErrPtr->message); else { /* Is this a Subversion-specific error code? */ if ((ErrPtr->apr_err > APR_OS_START_USEERR) && (ErrPtr->apr_err <= APR_OS_START_CANONERR)) msg = svn_strerror (ErrPtr->apr_err, errbuf, _countof (errbuf)); /* Otherwise, this must be an APR error code. */ else { svn_error_t *temp_err = NULL; const char * err_string = NULL; temp_err = svn_utf_cstring_to_utf8(&err_string, apr_strerror (ErrPtr->apr_err, errbuf, _countof (errbuf)-1), ErrPtr->pool); if (temp_err) { svn_error_clear (temp_err); msg = L"Can't recode error string from APR"; } else { msg = CUnicodeUtils::GetUnicode(err_string); } } } msg = CStringUtils::LinesWrap(msg, wrap); while (ErrPtr->child) { ErrPtr = ErrPtr->child; msg += L"\n"; if (ErrPtr->message) temp = CUnicodeUtils::GetUnicode(ErrPtr->message); else { /* Is this a Subversion-specific error code? */ if ((ErrPtr->apr_err > APR_OS_START_USEERR) && (ErrPtr->apr_err <= APR_OS_START_CANONERR)) temp = svn_strerror (ErrPtr->apr_err, errbuf, _countof (errbuf)); /* Otherwise, this must be an APR error code. */ else { svn_error_t *temp_err = NULL; const char * err_string = NULL; temp_err = svn_utf_cstring_to_utf8(&err_string, apr_strerror (ErrPtr->apr_err, errbuf, _countof (errbuf)-1), ErrPtr->pool); if (temp_err) { svn_error_clear (temp_err); temp = L"Can't recode error string from APR"; } else { temp = CUnicodeUtils::GetUnicode(err_string); } } } temp = CStringUtils::LinesWrap(temp, wrap); msg += temp; } temp.Empty(); if (svn_error_find_cause(Err, SVN_ERR_WC_LOCKED) && (Err->apr_err != SVN_ERR_WC_CLEANUP_REQUIRED)) temp.LoadString(IDS_SVNERR_RUNCLEANUP); #ifdef IDS_SVNERR_CHECKPATHORURL // add some hint text for some of the error messages switch (Err->apr_err) { case SVN_ERR_BAD_FILENAME: case SVN_ERR_BAD_URL: // please check the path or URL you've entered. temp.LoadString(IDS_SVNERR_CHECKPATHORURL); break; case SVN_ERR_WC_CLEANUP_REQUIRED: // do a "cleanup" temp.LoadString(IDS_SVNERR_RUNCLEANUP); break; case SVN_ERR_WC_NOT_UP_TO_DATE: case SVN_ERR_FS_TXN_OUT_OF_DATE: // do an update first temp.LoadString(IDS_SVNERR_UPDATEFIRST); break; case SVN_ERR_WC_CORRUPT: case SVN_ERR_WC_CORRUPT_TEXT_BASE: // do a "cleanup". If that doesn't work you need to do a fresh checkout. temp.LoadString(IDS_SVNERR_CLEANUPORFRESHCHECKOUT); break; case SVN_ERR_REPOS_POST_COMMIT_HOOK_FAILED: temp.LoadString(IDS_SVNERR_POSTCOMMITHOOKFAILED); break; case SVN_ERR_REPOS_POST_LOCK_HOOK_FAILED: temp.LoadString(IDS_SVNERR_POSTLOCKHOOKFAILED); break; case SVN_ERR_REPOS_POST_UNLOCK_HOOK_FAILED: temp.LoadString(IDS_SVNERR_POSTUNLOCKHOOKFAILED); break; case SVN_ERR_REPOS_HOOK_FAILURE: temp.LoadString(IDS_SVNERR_HOOKFAILED); break; case SVN_ERR_SQLITE_BUSY: temp.LoadString(IDS_SVNERR_SQLITEBUSY); break; default: break; } if ((Err->apr_err == SVN_ERR_FS_PATH_NOT_LOCKED)|| (Err->apr_err == SVN_ERR_FS_NO_SUCH_LOCK)|| (Err->apr_err == SVN_ERR_RA_NOT_LOCKED)) { // the lock has already been broken from another working copy temp.LoadString(IDS_SVNERR_UNLOCKFAILEDNOLOCK); } else if (SVN_ERR_IS_UNLOCK_ERROR(Err)) { // if you want to break the lock, use the "check for modifications" dialog temp.LoadString(IDS_SVNERR_UNLOCKFAILED); } if (!temp.IsEmpty()) { msg += L"\n" + temp; } #endif return msg; } return L""; }