pdf-preview-error.js 7.1 KB

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