pr_26086.patch 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. --- a/services/history-v1/api/controllers/project_import.js
  2. +++ b/services/history-v1/api/controllers/project_import.js
  3. @@ -35,6 +35,7 @@ async function importSnapshot(req, res) {
  4. try {
  5. snapshot = Snapshot.fromRaw(rawSnapshot)
  6. } catch (err) {
  7. + logger.warn({ err, projectId }, 'failed to import snapshot')
  8. return render.unprocessableEntity(res)
  9. }
  10. @@ -43,6 +44,7 @@ async function importSnapshot(req, res) {
  11. historyId = await chunkStore.initializeProject(projectId, snapshot)
  12. } catch (err) {
  13. if (err instanceof chunkStore.AlreadyInitialized) {
  14. + logger.warn({ err, projectId }, 'already initialized')
  15. return render.conflict(res)
  16. } else {
  17. throw err
  18. --- a/services/history-v1/api/controllers/projects.js
  19. +++ b/services/history-v1/api/controllers/projects.js
  20. @@ -34,6 +34,7 @@ async function initializeProject(req, res, next) {
  21. res.status(HTTPStatus.OK).json({ projectId })
  22. } catch (err) {
  23. if (err instanceof chunkStore.AlreadyInitialized) {
  24. + logger.warn({ err, projectId }, 'failed to initialize')
  25. render.conflict(res)
  26. } else {
  27. throw err
  28. @@ -242,11 +243,15 @@ async function createProjectBlob(req, res, next) {
  29. const sizeLimit = new StreamSizeLimit(maxUploadSize)
  30. await pipeline(req, sizeLimit, fs.createWriteStream(tmpPath))
  31. if (sizeLimit.sizeLimitExceeded) {
  32. + logger.warn(
  33. + { projectId, expectedHash, maxUploadSize },
  34. + 'blob exceeds size threshold'
  35. + )
  36. return render.requestEntityTooLarge(res)
  37. }
  38. const hash = await blobHash.fromFile(tmpPath)
  39. if (hash !== expectedHash) {
  40. - logger.debug({ hash, expectedHash }, 'Hash mismatch')
  41. + logger.warn({ projectId, hash, expectedHash }, 'Hash mismatch')
  42. return render.conflict(res, 'File hash mismatch')
  43. }
  44. @@ -343,6 +348,10 @@ async function copyProjectBlob(req, res, next) {
  45. targetBlobStore.getBlob(blobHash),
  46. ])
  47. if (!sourceBlob) {
  48. + logger.warn(
  49. + { sourceProjectId, targetProjectId, blobHash },
  50. + 'missing source blob when copying across projects'
  51. + )
  52. return render.notFound(res)
  53. }
  54. // Exit early if the blob exists in the target project.
  55. --- a/services/history-v1/app.js
  56. +++ b/services/history-v1/app.js
  57. @@ -100,11 +100,13 @@ function setupErrorHandling() {
  58. })
  59. }
  60. if (err.code === 'ENUM_MISMATCH') {
  61. + logger.warn({ err, projectId }, err.message)
  62. return res.status(HTTPStatus.UNPROCESSABLE_ENTITY).json({
  63. message: 'invalid enum value: ' + err.paramName,
  64. })
  65. }
  66. if (err.code === 'REQUIRED') {
  67. + logger.warn({ err, projectId }, err.message)
  68. return res.status(HTTPStatus.UNPROCESSABLE_ENTITY).json({
  69. message: err.message,
  70. })
  71. --- a/services/project-history/app/js/HistoryStoreManager.js
  72. +++ b/services/project-history/app/js/HistoryStoreManager.js
  73. @@ -35,7 +35,10 @@ class StringStream extends stream.Readable {
  74. _mocks.getMostRecentChunk = (projectId, historyId, callback) => {
  75. const path = `projects/${historyId}/latest/history`
  76. logger.debug({ projectId, historyId }, 'getting chunk from history service')
  77. - _requestChunk({ path, json: true }, callback)
  78. + _requestChunk({ path, json: true }, (err, chunk) => {
  79. + if (err) return callback(OError.tag(err))
  80. + callback(null, chunk)
  81. + })
  82. }
  83. /**
  84. @@ -54,7 +57,10 @@ export function getChunkAtVersion(projectId, historyId, version, callback) {
  85. { projectId, historyId, version },
  86. 'getting chunk from history service for version'
  87. )
  88. - _requestChunk({ path, json: true }, callback)
  89. + _requestChunk({ path, json: true }, (err, chunk) => {
  90. + if (err) return callback(OError.tag(err))
  91. + callback(null, chunk)
  92. + })
  93. }
  94. export function getMostRecentVersion(projectId, historyId, callback) {
  95. @@ -68,8 +74,10 @@ export function getMostRecentVersion(projectId, historyId, callback) {
  96. _.sortBy(chunk.chunk.history.changes || [], x => x.timestamp)
  97. )
  98. // find the latest project and doc versions in the chunk
  99. - _getLatestProjectVersion(projectId, chunk, (err1, projectVersion) =>
  100. + _getLatestProjectVersion(projectId, chunk, (err1, projectVersion) => {
  101. + if (err1) err1 = OError.tag(err1)
  102. _getLatestV2DocVersions(projectId, chunk, (err2, v2DocVersions) => {
  103. + if (err2) err2 = OError.tag(err2)
  104. // return the project and doc versions
  105. const projectStructureAndDocVersions = {
  106. project: projectVersion,
  107. @@ -83,7 +91,7 @@ export function getMostRecentVersion(projectId, historyId, callback) {
  108. chunk
  109. )
  110. })
  111. - )
  112. + })
  113. })
  114. }
  115. @@ -211,7 +219,10 @@ export function getProjectBlob(historyId, blobHash, callback) {
  116. logger.debug({ historyId, blobHash }, 'getting blob from history service')
  117. _requestHistoryService(
  118. { path: `projects/${historyId}/blobs/${blobHash}` },
  119. - callback
  120. + (err, blob) => {
  121. + if (err) return callback(OError.tag(err))
  122. + callback(null, blob)
  123. + }
  124. )
  125. }
  126. @@ -277,7 +288,10 @@ function createBlobFromString(historyId, data, fileId, callback) {
  127. (fsPath, cb) => {
  128. _createBlob(historyId, fsPath, cb)
  129. },
  130. - callback
  131. + (err, hash) => {
  132. + if (err) return callback(OError.tag(err))
  133. + callback(null, hash)
  134. + }
  135. )
  136. }
  137. @@ -330,7 +344,7 @@ export function createBlobForUpdate(projectId, historyId, update, callback) {
  138. try {
  139. ranges = HistoryBlobTranslator.createRangeBlobDataFromUpdate(update)
  140. } catch (error) {
  141. - return callback(error)
  142. + return callback(OError.tag(error))
  143. }
  144. createBlobFromString(
  145. historyId,
  146. @@ -338,7 +352,7 @@ export function createBlobForUpdate(projectId, historyId, update, callback) {
  147. `project-${projectId}-doc-${update.doc}`,
  148. (err, fileHash) => {
  149. if (err) {
  150. - return callback(err)
  151. + return callback(OError.tag(err))
  152. }
  153. if (ranges) {
  154. createBlobFromString(
  155. @@ -347,7 +361,7 @@ export function createBlobForUpdate(projectId, historyId, update, callback) {
  156. `project-${projectId}-doc-${update.doc}-ranges`,
  157. (err, rangesHash) => {
  158. if (err) {
  159. - return callback(err)
  160. + return callback(OError.tag(err))
  161. }
  162. logger.debug(
  163. { fileHash, rangesHash },
  164. @@ -415,7 +429,7 @@ export function createBlobForUpdate(projectId, historyId, update, callback) {
  165. },
  166. (err, fileHash) => {
  167. if (err) {
  168. - return callback(err)
  169. + return callback(OError.tag(err))
  170. }
  171. if (update.hash && update.hash !== fileHash) {
  172. logger.warn(
  173. @@ -447,7 +461,7 @@ export function createBlobForUpdate(projectId, historyId, update, callback) {
  174. },
  175. (err, fileHash) => {
  176. if (err) {
  177. - return callback(err)
  178. + return callback(OError.tag(err))
  179. }
  180. logger.debug({ fileHash }, 'created empty blob for file')
  181. callback(null, { file: fileHash })
  182. @@ -520,7 +534,10 @@ export function initializeProject(historyId, callback) {
  183. export function deleteProject(projectId, callback) {
  184. _requestHistoryService(
  185. { method: 'DELETE', path: `projects/${projectId}` },
  186. - callback
  187. + err => {
  188. + if (err) return callback(OError.tag(err))
  189. + callback(null)
  190. + }
  191. )
  192. }