Skip to content

Commit b27e093

Browse files
committed
🖋️ Adjust base64 file errors
1 parent dc97b0b commit b27e093

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

autoload/proompter/base64.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
" proompter.vim - Provide integration with local Ollama LLM API
33
" Maintainer: S0AndS0 <https://github.com/S0AndS0>
44
" URL: https://github.com/vim-utilities/proompter
5+
"
6+
" Note: pipes instead of process substitution is necessary to make GitHub
7+
" Actions play nice with tests, however, for those using the Linux Subsystem
8+
" on Windows or Cygwin there may be a performance hit :-(
59

610
""
711
"
@@ -29,6 +33,11 @@ function! proompter#base64#EncodeFile(path) abort
2933
if !len(a:path)
3034
throw 'No path value'
3135
endif
36+
37+
if !filereadable(a:path)
38+
throw 'Cannot read file -> ' . a:path.
39+
endif
40+
3241
let l:path = shellescape(a:path)
3342
return system('base64 --wrap=0 ' . l:path)
3443
endfunction
@@ -39,6 +48,11 @@ function! proompter#base64#DecodeToFile(string, path, flags = '') abort
3948
if !len(a:path)
4049
throw 'No path value'
4150
endif
51+
52+
if !filereadable(a:path)
53+
throw 'Cannot read file -> ' . a:path.
54+
endif
55+
4256
let l:path = shellescape(a:path)
4357
let l:string = shellescape(a:string)
4458
return system('printf "%s" ' . l:string . ' | base64 --decode > ' . l:path)

autoload/proompter/callback/prompt.vim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,21 @@ endfunction
3030
" See: {docs} :help readfile()
3131
function! proompter#callback#prompt#EncodeImagesFromFilePaths(paths, _configurations = g:proompter, _state = g:proompter_state) abort
3232
let l:encoded_images = []
33+
let l:skipped_paths = []
3334

3435
for l:path in a:paths
3536
if !filereadable(l:path)
36-
echow 'Cannot read image ->' l:path
37+
call add(l:skipped_paths, l:path)
3738
continue
3839
endif
3940

4041
call add(l:encoded_images, proompter#base64#EncodeFile(l:path))
4142
endfor
4243

44+
if len(l:skipped_paths)
45+
echoe 'l:skipped_paths ->' l:skipped_paths
46+
endif
47+
4348
return l:encoded_images
4449
endfunction
4550

0 commit comments

Comments
 (0)