async function localEval(groups, groupName, opaVersion) {
  const opa = await acquireOPAVersion(opaVersion) // Get the path (and download if necessary) the required version of OPA.

  const [args, moduleFilenameMap] = await prepEval(groups, groupName) // Save the group data to temporary files

  try {
    return (await execFile(opa, args('pretty'))).stdout.replace(/\n$/, '') // Evaluate, retrieving the pretty-formatted output
  } catch (e) {
    if (e.stdout) { // OPA returned an error message
      let pretty = e.stdout.replace(/\n$/, '')
      // Replace the module file names with what the playground will use.
      for (let [tmp, replacement] of Object.entries(moduleFilenameMap)) {
        pretty = pretty.replace(new RegExp(tmp, 'g'), replacement)
      }

      if (pretty === 'undefined') { // Special undefined case, use the same message as the playground.
        throw new OPAErrors('undefined decision', undefined)

      } else { // Some other error occurred, reevaluate to get the JSON-formatted version of the errors so that they can be compared against what the block expects.
        try {
          await execFile(opa, args('json'))
          throw new Error('subsequent eval of failing evaluation did not fail')
        } catch (e2) {
          if (e2.stdout) { // Reevaluation seems to have worked
            let opaErrors
            try { // Parse the reevaluation result into an OPAErrors object to be thrown.
              let parsed = JSON.parse(e2.stdout)
              if (parsed.errors) {
                opaErrors = new OPAErrors(pretty, parsed.errors)
              } else {
                opaErrors = new OPAErrors(pretty, parsed.error)
              }
            } catch (e3) {
              throw new ChainedError('invalid response while trying to get details about an evaluation failure', e3)
            }
            throw opaErrors
          } else { // Reevaluation didn't produce output
            throw new ChainedError('an error occurred while trying to get details about an evaluation failure', e2)
          }
        }
      }
    } else { // OPA didn't return an error message, probably some problem calling it.
      throw new ChainedError(e.stderr ? `OPA: ${e.stderr}` : 'unable to perform local evaluation', e) // Some OPA error. This particularly applies to parse errors, they occur at a different point internally and are not reported correctly; it's fine though, doc examples probably shouldn't cause them.
    }
  }
}
// Evaluate the group using a local OPA binary. Either returns a string suitable for a code block or throws an error whose message is user-friendly. If the OPA evaluation itself failed, throws an OPAErrors instance.
Evaluate the group using a local OPA binary. Either returns a string suitable for a code block or throws an error whose message is user-friendly. If the OPA evaluation itself failed, throws an OPAErrors instance.
Evaluate the group using a local OPA binary . Either returns a string suitable for a code block or throws an error whose message is user - friendly . If the OPA evaluation itself failed throws an OPAErrors instance .
async function localEval(groups, groupName, opaVersion) {
  const opa = await acquireOPAVersion(opaVersion) 
  const [args, moduleFilenameMap] = await prepEval(groups, groupName) 
  try {
    return (await execFile(opa, args('pretty'))).stdout.replace(/\n$/, '') 
  } catch (e) {
    if (e.stdout) { 
      let pretty = e.stdout.replace(/\n$/, '')
      for (let [tmp, replacement] of Object.entries(moduleFilenameMap)) {
        pretty = pretty.replace(new RegExp(tmp, 'g'), replacement)
      }
      if (pretty === 'undefined') { 
        throw new OPAErrors('undefined decision', undefined)
      } else { 
        try {
          await execFile(opa, args('json'))
          throw new Error('subsequent eval of failing evaluation did not fail')
        } catch (e2) {
          if (e2.stdout) { 
            let opaErrors
            try { 
              let parsed = JSON.parse(e2.stdout)
              if (parsed.errors) {
                opaErrors = new OPAErrors(pretty, parsed.errors)
              } else {
                opaErrors = new OPAErrors(pretty, parsed.error)
              }
            } catch (e3) {
              throw new ChainedError('invalid response while trying to get details about an evaluation failure', e3)
            }
            throw opaErrors
          } else { 
            throw new ChainedError('an error occurred while trying to get details about an evaluation failure', e2)
          }
        }
      }
    } else { 
      throw new ChainedError(e.stderr ? `OPA: ${e.stderr}` : 'unable to perform local evaluation', e) 
    }
  }
}
async function localEval ( groups , groupName , opaVersion ) { const opa = await acquireOPAVersion ( opaVersion ) const [ args , moduleFilenameMap ] = await prepEval ( groups , groupName ) try { return ( await execFile ( opa , args ( 'pretty' ) ) ) . stdout . replace ( / \n$ / , '' ) } catch ( e ) { if ( e . stdout ) { let pretty = e . stdout . replace ( / \n$ / , '' ) for ( let [ tmp , replacement ] of Object . entries ( moduleFilenameMap ) ) { pretty = pretty . replace ( new RegExp ( tmp , 'g' ) , replacement ) } if ( pretty === 'undefined' ) { throw new OPAErrors ( 'undefined decision' , undefined ) } else { try { await execFile ( opa , args ( 'json' ) ) throw new Error ( 'subsequent eval of failing evaluation did not fail' ) } catch ( e2 ) { if ( e2 . stdout ) { let opaErrors try { let parsed = JSON . parse ( e2 . stdout ) if ( parsed . errors ) { opaErrors = new OPAErrors ( pretty , parsed . errors ) } else { opaErrors = new OPAErrors ( pretty , parsed . error ) } } catch ( e3 ) { throw new ChainedError ( 'invalid response while trying to get details about an evaluation failure' , e3 ) } throw opaErrors } else { throw new ChainedError ( 'an error occurred while trying to get details about an evaluation failure' , e2 ) } } } } else { throw new ChainedError ( e . stderr ? ` ${ e . stderr } ` : 'unable to perform local evaluation' , e ) } } }
Evaluate the group using a local OPA binary.
Evaluate the group using a local OPA binary .
// Get the path (and download if necessary) the required version of OPA. // Save the group data to temporary files // Evaluate, retrieving the pretty-formatted output // OPA returned an error message // Replace the module file names with what the playground will use. // Special undefined case, use the same message as the playground. // Some other error occurred, reevaluate to get the JSON-formatted version of the errors so that they can be compared against what the block expects. // Reevaluation seems to have worked // Parse the reevaluation result into an OPAErrors object to be thrown. // Reevaluation didn't produce output // OPA didn't return an error message, probably some problem calling it. // Some OPA error. This particularly applies to parse errors, they occur at a different point internally and are not reported correctly; it's fine though, doc examples probably shouldn't cause them.