<commit_before>﻿namespace SourceLink.SymbolStore

open System
open System.IO
open SourceLink.SymbolStore.CorSym          

type PdbReader(reader:ISymUnmanagedReader, sessionCookie:IntPtr, fileName:string) =

    let moduleCookie =
        if String.IsNullOrEmpty fileName then 0L
        else SrcSrv.LoadModule(sessionCookie, fileName, reader.AsSourceServer)
    let isSourceIndexed = moduleCookie <> 0L
    
    new(pdb, sessionCookie, fileName) =
        PdbReader(ISymUnmanagedReader.Create pdb, sessionCookie, fileName)

    new(pdb:Stream) =
        PdbReader(pdb, IntPtr.Zero, null)
    
    member x.IsSourceIndexed = isSourceIndexed

    member x.GetDownloadUrl sourceFilePath =
        if isSourceIndexed then
            SrcSrv.GetFileUrl(sessionCookie, moduleCookie, sourceFilePath) |> Option.ofNull
        else None

    member x.Reader = reader
    member x.Documents = reader.Documents
    member x.GetMethod token = reader.GetMethod token<commit_msg>#73 better error message for invalid pdb<commit_after>﻿namespace SourceLink.SymbolStore

open System
open System.IO
open SourceLink.SymbolStore.CorSym          

type PdbReader(reader:ISymUnmanagedReader, sessionCookie:IntPtr, fileName:string) =
    
    let moduleCookie =
        if String.IsNullOrEmpty fileName then 0L
        else SrcSrv.LoadModule(sessionCookie, fileName, reader.AsSourceServer)
    let isSourceIndexed = moduleCookie <> 0L
    
    static let createReader pdb fileName = 
        try
            ISymUnmanagedReader.Create pdb
        with
            | _ -> failwithf "error reading pdb file '%s'" fileName

    new(pdb, sessionCookie, fileName) =
        PdbReader(createReader pdb fileName, sessionCookie, fileName)

    new(pdb:Stream) =
        PdbReader(pdb, IntPtr.Zero, null)
    
    member x.IsSourceIndexed = isSourceIndexed

    member x.GetDownloadUrl sourceFilePath =
        if isSourceIndexed then
            SrcSrv.GetFileUrl(sessionCookie, moduleCookie, sourceFilePath) |> Option.ofNull
        else None

    member x.Reader = reader
    member x.Documents = reader.Documents
    member x.GetMethod token = reader.GetMethod token
{'fraction_non_alphanumeric': 0.06638616175783076, 'fraction_numerical': 0.002805049088359046, 'mean_word_length': 3.2043222003929275, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6403259', 'n_tokens_mistral': 618, 'n_tokens_neox': 610, 'n_words': 150}