Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internals: Fail with clear error message if scripts not allowed by PS execuction policy (#2) #9

Merged
merged 3 commits into from
Oct 6, 2024

Conversation

markheckmann
Copy link
Contributor

@markheckmann markheckmann commented Oct 3, 2024

Fail with clear error message if PowerShell (PS) execution strategy does not allow running scripts in Windows (#2).


BEFORE

Reason for failure is unclear for user.

library(doconv)

file <- system.file(package = "doconv", "doc-examples/example.pptx")
out <- pptx2pdf(input = file, output = tempfile(fileext = ".pdf"))
#> Error: could not convert C:/Users/heckm/AppData/Local/R/win-library/4.4/doconv/doc-examples/example.pptx

file <- system.file(package = "doconv", "doc-examples/example.docx")
out <- docx2pdf(input = file, output = tempfile(fileext = ".pdf"))
#> Error: could not convert C:/Users/heckm/AppData/Local/R/win-library/4.4/doconv/doc-examples/example.docxDie Datei "C:\Users\heckm\AppData\Local\Temp\RtmpiSs1xl\file34605f593a78.ps1" kann nicht geladen werden, da die 
#> Ausfhrung von Skripts auf diesem System deaktiviert ist. Weitere Informationen finden Sie unter 
#> "about_Execution_Policies" (https:/go.microsoft.com/fwlink/?LinkID=135170).
#>     + CategoryInfo          : Sicherheitsfehler: (:) [], ParentContainsErrorRecordException
#>     + FullyQualifiedErrorId : UnauthorizedAccess

docx_out <- tempfile(fileext = ".docx")
file.copy(file, docx_out)
#> [1] TRUE
docx_update(input = docx_out)
#> Error: could not update C:/Users/heckm/AppData/Local/Temp/RtmpiSs1xl/file3460204023fd.docx

NEW

User is advised what to do.

library(doconv)

file <- system.file(package = "doconv", "doc-examples/example.pptx")
out <- pptx2pdf(input = file, output = tempfile(fileext = ".pdf"))
#> Error: Conversion failed.
#> Your PowerShell execution policy 'Restricted' prevents script execution.
#> Run one of the following commands in PS as admin to enable script execution: 
#>   `Set-ExecutionPolicy Bypass`
#>   `Set-ExecutionPolicy Unrestricted`

file <- system.file(package = "doconv", "doc-examples/example.docx")
out <- docx2pdf(input = file, output = tempfile(fileext = ".pdf"))
#> Error: Conversion failed.
#> Your PowerShell execution policy 'Restricted' prevents script execution.
#> Run one of the following commands in PS as admin to enable script execution: 
#>   `Set-ExecutionPolicy Bypass`
#>   `Set-ExecutionPolicy Unrestricted`

docx_out <- tempfile(fileext = ".docx")
file.copy(file, docx_out)
#> [1] TRUE
docx_update(input = docx_out)
#> Error: Conversion failed.
#> Your PowerShell execution policy 'Restricted' prevents script execution.
#> Run one of the following commands in PS as admin to enable script execution: 
#>   `Set-ExecutionPolicy Bypass`
#>   `Set-ExecutionPolicy Unrestricted`

Created on 2024-10-04 with reprex v2.1.1

Stop if PowerShell (PS) execution strategy does not allow running scripts and advise user. PS scripts are required for certain actions on Windows (ardata-fr#2).
@markheckmann markheckmann changed the title Internals: Fail with clear message if PS scripts not allowed (#2) Internals: Fail with clear error message if scripts not allowed by PS execuction policy (#2) Oct 4, 2024
@davidgohel
Copy link
Member

thanks for the really nice improvement.

@davidgohel davidgohel merged commit bc7ca94 into ardata-fr:main Oct 6, 2024
3 checks passed
@markheckmann markheckmann deleted the issue_2_ps_exec_policy branch October 6, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants