pdf-preview-error.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. import PropTypes from 'prop-types'
  2. import { useTranslation, Trans } from 'react-i18next'
  3. import { memo, useCallback } from 'react'
  4. import { Button } from 'react-bootstrap'
  5. import PdfLogEntry from './pdf-log-entry'
  6. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  7. import { useStopOnFirstError } from '../../../shared/hooks/use-stop-on-first-error'
  8. import getMeta from '../../../utils/meta'
  9. function PdfPreviewError({ error }) {
  10. const { t } = useTranslation()
  11. const { startCompile } = useCompileContext()
  12. switch (error) {
  13. case 'rendering-error-new-domain':
  14. return (
  15. <PdfLogEntry
  16. headerTitle={t('pdf_rendering_error')}
  17. formattedContent={
  18. <Trans
  19. i18nKey="new_compile_domain_trouble_shooting"
  20. values={{
  21. compilesUserContentDomain: new URL(
  22. getMeta('ol-compilesUserContentDomain')
  23. ).hostname,
  24. }}
  25. components={[
  26. <code key="domain" />,
  27. /* eslint-disable-next-line jsx-a11y/anchor-has-content */
  28. <a
  29. href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems"
  30. target="_blank"
  31. key="troubleshooting-link"
  32. />,
  33. ]}
  34. />
  35. }
  36. level="warning"
  37. />
  38. )
  39. case 'rendering-error-expected':
  40. return (
  41. <PdfLogEntry
  42. headerTitle={t('pdf_rendering_error')}
  43. formattedContent={
  44. <>
  45. <Trans i18nKey="something_went_wrong_rendering_pdf_expected">
  46. <Button
  47. bsSize="xs"
  48. bsStyle="info"
  49. onClick={() => startCompile()}
  50. />
  51. </Trans>
  52. <br />
  53. <br />
  54. <Trans
  55. i18nKey="last_resort_trouble_shooting_guide"
  56. components={[
  57. // eslint-disable-next-line jsx-a11y/anchor-has-content
  58. <a
  59. href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems"
  60. target="_blank"
  61. key="troubleshooting-link"
  62. />,
  63. ]}
  64. />
  65. </>
  66. }
  67. level="warning"
  68. />
  69. )
  70. case 'rendering-error':
  71. return (
  72. <ErrorLogEntry title={t('pdf_rendering_error')}>
  73. {t('something_went_wrong_rendering_pdf')}
  74. &nbsp;
  75. <Trans
  76. i18nKey="try_recompile_project_or_troubleshoot"
  77. components={[
  78. // eslint-disable-next-line jsx-a11y/anchor-has-content
  79. <a
  80. href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems"
  81. target="_blank"
  82. key="troubleshooting-link"
  83. />,
  84. ]}
  85. />
  86. </ErrorLogEntry>
  87. )
  88. case 'clsi-maintenance':
  89. return (
  90. <ErrorLogEntry title={t('server_error')}>
  91. {t('clsi_maintenance')}
  92. </ErrorLogEntry>
  93. )
  94. case 'clsi-unavailable':
  95. return (
  96. <ErrorLogEntry title={t('server_error')}>
  97. {t('clsi_unavailable')}
  98. </ErrorLogEntry>
  99. )
  100. case 'too-recently-compiled':
  101. return (
  102. <ErrorLogEntry title={t('server_error')}>
  103. {t('too_recently_compiled')}
  104. </ErrorLogEntry>
  105. )
  106. case 'terminated':
  107. return (
  108. <ErrorLogEntry title={t('terminated')}>
  109. {t('compile_terminated_by_user')}
  110. </ErrorLogEntry>
  111. )
  112. case 'rate-limited':
  113. return (
  114. <ErrorLogEntry title={t('pdf_compile_rate_limit_hit')}>
  115. {t('project_flagged_too_many_compiles')}
  116. </ErrorLogEntry>
  117. )
  118. case 'compile-in-progress':
  119. return (
  120. <ErrorLogEntry title={t('pdf_compile_in_progress_error')}>
  121. {t('pdf_compile_try_again')}
  122. </ErrorLogEntry>
  123. )
  124. case 'auto-compile-disabled':
  125. return (
  126. <ErrorLogEntry title={t('autocompile_disabled')}>
  127. {t('autocompile_disabled_reason')}
  128. </ErrorLogEntry>
  129. )
  130. case 'project-too-large':
  131. return (
  132. <ErrorLogEntry title={t('project_too_large')}>
  133. {t('project_too_much_editable_text')}
  134. </ErrorLogEntry>
  135. )
  136. case 'timedout':
  137. return <TimedOutLogEntry />
  138. case 'failure':
  139. return (
  140. <ErrorLogEntry title={t('no_pdf_error_title')}>
  141. {t('no_pdf_error_explanation')}
  142. <ul className="log-entry-formatted-content-list">
  143. <li>{t('no_pdf_error_reason_unrecoverable_error')}</li>
  144. <li>
  145. <Trans
  146. i18nKey="no_pdf_error_reason_no_content"
  147. components={{ code: <code /> }}
  148. />
  149. </li>
  150. <li>
  151. <Trans
  152. i18nKey="no_pdf_error_reason_output_pdf_already_exists"
  153. components={{ code: <code /> }}
  154. />
  155. </li>
  156. </ul>
  157. </ErrorLogEntry>
  158. )
  159. case 'clear-cache':
  160. return (
  161. <ErrorLogEntry title={t('server_error')}>
  162. {t('somthing_went_wrong_compiling')}
  163. </ErrorLogEntry>
  164. )
  165. case 'pdf-viewer-loading-error':
  166. return (
  167. <ErrorLogEntry title={t('pdf_rendering_error')}>
  168. <Trans
  169. i18nKey="something_went_wrong_loading_pdf_viewer"
  170. components={[
  171. <strong key="strong-" />,
  172. // eslint-disable-next-line jsx-a11y/anchor-has-content
  173. <a
  174. href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems"
  175. target="_blank"
  176. key="troubleshooting-link"
  177. />,
  178. // eslint-disable-next-line jsx-a11y/anchor-has-content
  179. <a key="contact-link" target="_blank" href="/contact" />,
  180. ]}
  181. />
  182. </ErrorLogEntry>
  183. )
  184. case 'validation-problems':
  185. return null // handled elsewhere
  186. case 'error':
  187. default:
  188. return (
  189. <ErrorLogEntry title={t('server_error')}>
  190. {t('somthing_went_wrong_compiling')}
  191. </ErrorLogEntry>
  192. )
  193. }
  194. }
  195. PdfPreviewError.propTypes = {
  196. error: PropTypes.string.isRequired,
  197. }
  198. export default memo(PdfPreviewError)
  199. function ErrorLogEntry({ title, headerIcon, children }) {
  200. const { t } = useTranslation()
  201. return (
  202. <PdfLogEntry
  203. headerTitle={title}
  204. headerIcon={headerIcon}
  205. formattedContent={children}
  206. entryAriaLabel={t('compile_error_entry_description')}
  207. level="error"
  208. />
  209. )
  210. }
  211. ErrorLogEntry.propTypes = {
  212. title: PropTypes.string.isRequired,
  213. headerIcon: PropTypes.element,
  214. children: PropTypes.any.isRequired,
  215. }
  216. function TimedOutLogEntry() {
  217. const { t } = useTranslation()
  218. const { enableStopOnFirstError } = useStopOnFirstError({
  219. eventSource: 'timeout',
  220. })
  221. const { startCompile, lastCompileOptions, setAnimateCompileDropdownArrow } =
  222. useCompileContext()
  223. const handleEnableStopOnFirstErrorClick = useCallback(() => {
  224. enableStopOnFirstError()
  225. startCompile({ stopOnFirstError: true })
  226. setAnimateCompileDropdownArrow(true)
  227. }, [enableStopOnFirstError, startCompile, setAnimateCompileDropdownArrow])
  228. return (
  229. <ErrorLogEntry title={t('timedout')}>
  230. <p>{t('project_timed_out_intro')}</p>
  231. <ul>
  232. <li>
  233. <Trans
  234. i18nKey="project_timed_out_optimize_images"
  235. components={[
  236. // eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
  237. <a href="https://www.overleaf.com/learn/how-to/Optimising_very_large_image_files" />,
  238. ]}
  239. />
  240. </li>
  241. <li>
  242. <Trans
  243. i18nKey="project_timed_out_fatal_error"
  244. components={[
  245. // eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
  246. <a href="https://www.overleaf.com/learn/how-to/Why_do_I_keep_getting_the_compile_timeout_error_message%3F#Fatal_compile_errors_blocking_the_compilation" />,
  247. ]}
  248. />
  249. {!lastCompileOptions.stopOnFirstError && (
  250. <>
  251. {' '}
  252. <Trans
  253. i18nKey="project_timed_out_enable_stop_on_first_error"
  254. components={[
  255. // eslint-disable-next-line react/jsx-key
  256. <Button
  257. bsSize="xs"
  258. bsStyle="info"
  259. onClick={handleEnableStopOnFirstErrorClick}
  260. />,
  261. ]}
  262. />{' '}
  263. </>
  264. )}
  265. </li>
  266. </ul>
  267. <p>
  268. <Trans
  269. i18nKey="project_timed_out_learn_more"
  270. components={[
  271. // eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
  272. <a href="https://www.overleaf.com/learn/how-to/Why_do_I_keep_getting_the_compile_timeout_error_message%3F" />,
  273. ]}
  274. />
  275. </p>
  276. </ErrorLogEntry>
  277. )
  278. }
  279. TimedOutLogEntry.propTypes = {}