pdf-preview-error.jsx 9.1 KB

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