messages.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. Copyright 2018 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import '../../_version.js';
  8. export const messages = {
  9. 'invalid-value': ({ paramName, validValueDescription, value }) => {
  10. if (!paramName || !validValueDescription) {
  11. throw new Error(`Unexpected input to 'invalid-value' error.`);
  12. }
  13. return `The '${paramName}' parameter was given a value with an ` +
  14. `unexpected value. ${validValueDescription} Received a value of ` +
  15. `${JSON.stringify(value)}.`;
  16. },
  17. 'not-an-array': ({ moduleName, className, funcName, paramName }) => {
  18. if (!moduleName || !className || !funcName || !paramName) {
  19. throw new Error(`Unexpected input to 'not-an-array' error.`);
  20. }
  21. return `The parameter '${paramName}' passed into ` +
  22. `'${moduleName}.${className}.${funcName}()' must be an array.`;
  23. },
  24. 'incorrect-type': ({ expectedType, paramName, moduleName, className, funcName }) => {
  25. if (!expectedType || !paramName || !moduleName || !funcName) {
  26. throw new Error(`Unexpected input to 'incorrect-type' error.`);
  27. }
  28. return `The parameter '${paramName}' passed into ` +
  29. `'${moduleName}.${className ? (className + '.') : ''}` +
  30. `${funcName}()' must be of type ${expectedType}.`;
  31. },
  32. 'incorrect-class': ({ expectedClass, paramName, moduleName, className, funcName, isReturnValueProblem }) => {
  33. if (!expectedClass || !moduleName || !funcName) {
  34. throw new Error(`Unexpected input to 'incorrect-class' error.`);
  35. }
  36. if (isReturnValueProblem) {
  37. return `The return value from ` +
  38. `'${moduleName}.${className ? (className + '.') : ''}${funcName}()' ` +
  39. `must be an instance of class ${expectedClass.name}.`;
  40. }
  41. return `The parameter '${paramName}' passed into ` +
  42. `'${moduleName}.${className ? (className + '.') : ''}${funcName}()' ` +
  43. `must be an instance of class ${expectedClass.name}.`;
  44. },
  45. 'missing-a-method': ({ expectedMethod, paramName, moduleName, className, funcName }) => {
  46. if (!expectedMethod || !paramName || !moduleName || !className
  47. || !funcName) {
  48. throw new Error(`Unexpected input to 'missing-a-method' error.`);
  49. }
  50. return `${moduleName}.${className}.${funcName}() expected the ` +
  51. `'${paramName}' parameter to expose a '${expectedMethod}' method.`;
  52. },
  53. 'add-to-cache-list-unexpected-type': ({ entry }) => {
  54. return `An unexpected entry was passed to ` +
  55. `'workbox-precaching.PrecacheController.addToCacheList()' The entry ` +
  56. `'${JSON.stringify(entry)}' isn't supported. You must supply an array of ` +
  57. `strings with one or more characters, objects with a url property or ` +
  58. `Request objects.`;
  59. },
  60. 'add-to-cache-list-conflicting-entries': ({ firstEntry, secondEntry }) => {
  61. if (!firstEntry || !secondEntry) {
  62. throw new Error(`Unexpected input to ` +
  63. `'add-to-cache-list-duplicate-entries' error.`);
  64. }
  65. return `Two of the entries passed to ` +
  66. `'workbox-precaching.PrecacheController.addToCacheList()' had the URL ` +
  67. `${firstEntry._entryId} but different revision details. Workbox is ` +
  68. `unable to cache and version the asset correctly. Please remove one ` +
  69. `of the entries.`;
  70. },
  71. 'plugin-error-request-will-fetch': ({ thrownError }) => {
  72. if (!thrownError) {
  73. throw new Error(`Unexpected input to ` +
  74. `'plugin-error-request-will-fetch', error.`);
  75. }
  76. return `An error was thrown by a plugins 'requestWillFetch()' method. ` +
  77. `The thrown error message was: '${thrownError.message}'.`;
  78. },
  79. 'invalid-cache-name': ({ cacheNameId, value }) => {
  80. if (!cacheNameId) {
  81. throw new Error(`Expected a 'cacheNameId' for error 'invalid-cache-name'`);
  82. }
  83. return `You must provide a name containing at least one character for ` +
  84. `setCacheDetails({${cacheNameId}: '...'}). Received a value of ` +
  85. `'${JSON.stringify(value)}'`;
  86. },
  87. 'unregister-route-but-not-found-with-method': ({ method }) => {
  88. if (!method) {
  89. throw new Error(`Unexpected input to ` +
  90. `'unregister-route-but-not-found-with-method' error.`);
  91. }
  92. return `The route you're trying to unregister was not previously ` +
  93. `registered for the method type '${method}'.`;
  94. },
  95. 'unregister-route-route-not-registered': () => {
  96. return `The route you're trying to unregister was not previously ` +
  97. `registered.`;
  98. },
  99. 'queue-replay-failed': ({ name }) => {
  100. return `Replaying the background sync queue '${name}' failed.`;
  101. },
  102. 'duplicate-queue-name': ({ name }) => {
  103. return `The Queue name '${name}' is already being used. ` +
  104. `All instances of backgroundSync.Queue must be given unique names.`;
  105. },
  106. 'expired-test-without-max-age': ({ methodName, paramName }) => {
  107. return `The '${methodName}()' method can only be used when the ` +
  108. `'${paramName}' is used in the constructor.`;
  109. },
  110. 'unsupported-route-type': ({ moduleName, className, funcName, paramName }) => {
  111. return `The supplied '${paramName}' parameter was an unsupported type. ` +
  112. `Please check the docs for ${moduleName}.${className}.${funcName} for ` +
  113. `valid input types.`;
  114. },
  115. 'not-array-of-class': ({ value, expectedClass, moduleName, className, funcName, paramName }) => {
  116. return `The supplied '${paramName}' parameter must be an array of ` +
  117. `'${expectedClass}' objects. Received '${JSON.stringify(value)},'. ` +
  118. `Please check the call to ${moduleName}.${className}.${funcName}() ` +
  119. `to fix the issue.`;
  120. },
  121. 'max-entries-or-age-required': ({ moduleName, className, funcName }) => {
  122. return `You must define either config.maxEntries or config.maxAgeSeconds` +
  123. `in ${moduleName}.${className}.${funcName}`;
  124. },
  125. 'statuses-or-headers-required': ({ moduleName, className, funcName }) => {
  126. return `You must define either config.statuses or config.headers` +
  127. `in ${moduleName}.${className}.${funcName}`;
  128. },
  129. 'invalid-string': ({ moduleName, funcName, paramName }) => {
  130. if (!paramName || !moduleName || !funcName) {
  131. throw new Error(`Unexpected input to 'invalid-string' error.`);
  132. }
  133. return `When using strings, the '${paramName}' parameter must start with ` +
  134. `'http' (for cross-origin matches) or '/' (for same-origin matches). ` +
  135. `Please see the docs for ${moduleName}.${funcName}() for ` +
  136. `more info.`;
  137. },
  138. 'channel-name-required': () => {
  139. return `You must provide a channelName to construct a ` +
  140. `BroadcastCacheUpdate instance.`;
  141. },
  142. 'invalid-responses-are-same-args': () => {
  143. return `The arguments passed into responsesAreSame() appear to be ` +
  144. `invalid. Please ensure valid Responses are used.`;
  145. },
  146. 'expire-custom-caches-only': () => {
  147. return `You must provide a 'cacheName' property when using the ` +
  148. `expiration plugin with a runtime caching strategy.`;
  149. },
  150. 'unit-must-be-bytes': ({ normalizedRangeHeader }) => {
  151. if (!normalizedRangeHeader) {
  152. throw new Error(`Unexpected input to 'unit-must-be-bytes' error.`);
  153. }
  154. return `The 'unit' portion of the Range header must be set to 'bytes'. ` +
  155. `The Range header provided was "${normalizedRangeHeader}"`;
  156. },
  157. 'single-range-only': ({ normalizedRangeHeader }) => {
  158. if (!normalizedRangeHeader) {
  159. throw new Error(`Unexpected input to 'single-range-only' error.`);
  160. }
  161. return `Multiple ranges are not supported. Please use a single start ` +
  162. `value, and optional end value. The Range header provided was ` +
  163. `"${normalizedRangeHeader}"`;
  164. },
  165. 'invalid-range-values': ({ normalizedRangeHeader }) => {
  166. if (!normalizedRangeHeader) {
  167. throw new Error(`Unexpected input to 'invalid-range-values' error.`);
  168. }
  169. return `The Range header is missing both start and end values. At least ` +
  170. `one of those values is needed. The Range header provided was ` +
  171. `"${normalizedRangeHeader}"`;
  172. },
  173. 'no-range-header': () => {
  174. return `No Range header was found in the Request provided.`;
  175. },
  176. 'range-not-satisfiable': ({ size, start, end }) => {
  177. return `The start (${start}) and end (${end}) values in the Range are ` +
  178. `not satisfiable by the cached response, which is ${size} bytes.`;
  179. },
  180. 'attempt-to-cache-non-get-request': ({ url, method }) => {
  181. return `Unable to cache '${url}' because it is a '${method}' request and ` +
  182. `only 'GET' requests can be cached.`;
  183. },
  184. 'cache-put-with-no-response': ({ url }) => {
  185. return `There was an attempt to cache '${url}' but the response was not ` +
  186. `defined.`;
  187. },
  188. 'no-response': ({ url, error }) => {
  189. let message = `The strategy could not generate a response for '${url}'.`;
  190. if (error) {
  191. message += ` The underlying error is ${error}.`;
  192. }
  193. return message;
  194. },
  195. 'bad-precaching-response': ({ url, status }) => {
  196. return `The precaching request for '${url}' failed with an HTTP ` +
  197. `status of ${status}.`;
  198. },
  199. 'non-precached-url': ({ url }) => {
  200. return `createHandlerBoundToURL('${url}') was called, but that URL is ` +
  201. `not precached. Please pass in a URL that is precached instead.`;
  202. },
  203. 'add-to-cache-list-conflicting-integrities': ({ url }) => {
  204. return `Two of the entries passed to ` +
  205. `'workbox-precaching.PrecacheController.addToCacheList()' had the URL ` +
  206. `${url} with different integrity values. Please remove one of them.`;
  207. },
  208. 'missing-precache-entry': ({ cacheName, url }) => {
  209. return `Unable to find a precached response in ${cacheName} for ${url}.`;
  210. },
  211. };