pdf-preview-error.js 7.3 KB

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