Error when file does not exist

This commit is contained in:
Shreyas Goenka 2023-03-17 02:44:15 +01:00
parent c9340d6317
commit c98671a08b
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
2 changed files with 6 additions and 5 deletions

View File

@ -3,7 +3,6 @@ package mutator
import (
"context"
"fmt"
"os"
"path"
"path/filepath"
"strings"
@ -35,10 +34,6 @@ func (m *translateNotebookPaths) rewritePath(b *bundle.Bundle, p *string) error
absPath := filepath.Join(b.Config.Path, relPath)
nb, _, err := notebook.Detect(absPath)
if err != nil {
// Ignore if this file doesn't exist. Maybe it's an absolute workspace path?
if os.IsNotExist(err) {
return nil
}
return fmt.Errorf("unable to determine if %s is a notebook: %w", relPath, err)
}

View File

@ -3,6 +3,8 @@ package notebook
import (
"bufio"
"bytes"
"errors"
"fmt"
"io"
"os"
"path/filepath"
@ -39,6 +41,10 @@ func readHeader(path string) ([]byte, error) {
func Detect(path string) (notebook bool, language workspace.Language, err error) {
header := ""
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
return false, "", fmt.Errorf("file %s does not exist", path)
}
// Determine which header to expect based on filename extension.
ext := strings.ToLower(filepath.Ext(path))
switch ext {