pdf-preview-error.js 8.1 KB

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