messages.mjs 9.1 KB

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